Questions tagged [qmainwindow]

QMainWindow is a class in Qt library that implements the main window of an application.

As a main window for the application, QMainWindow is different from an ordinary widget. It has a menu bar on the top, a status bar, it can also have toolbars and dock widgets.

It also have a so-called Central Widget, which can be occupied by any other widgets.

Qt also allows one to easily implement single- and multiply-document-interfaces with this class.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

516 questions
39
votes
1 answer

How to set QMainWindow title

How do I set the title of a QMainWindow? I tried googling and found setCaption(), but it appears it no longer works in Qt 4.
houbysoft
  • 32,532
  • 24
  • 103
  • 156
36
votes
4 answers

Qt: Set size of QMainWindow

I'm new to Qt, so I wonder whether there is a way to set the size of a QMainWindow to (for example) 70% of the user's desktop.I tried the stretch factor but it didn't work. QWidget::setFixedSize worked but only with a pixel number, I think.
dadod2
  • 515
  • 1
  • 6
  • 11
34
votes
1 answer

Multiple QMainWindow instances?

The QMainWindow is the main window in a Qt application. So usually you'd have only one, but would it be possible at all to have multiple QMainWindow instances in your application? I am working on integrating a Qt-based GUI application B into…
andreas buykx
  • 12,608
  • 10
  • 62
  • 76
30
votes
5 answers

PyQt: RuntimeError: wrapped C/C++ object has been deleted

If I run this code: #!/usr/local/bin/ python3 import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Window(QMainWindow): def __init__(self): super().__init__() self.button1 = QPushButton("1") …
Brian
  • 3,453
  • 2
  • 27
  • 39
24
votes
3 answers

PyQt - how to add separate UI widget to QMainWindow

I've only recently started programming and Python (PyQt) in particular. I have my main QMainWindow class. But I wanted to separate it from UI widgets, so that all windows stuff (menus, toolbars, common buttons) are in QMainWindow, but all program/UI…
linuxoid
  • 1,415
  • 3
  • 14
  • 32
24
votes
5 answers

How to set a window icon with PyQt5?

from PyQt5 import QtWidgets, QtGui from PyQt5.QtWidgets import * from PyQt5.QtCore import * class Application(QMainWindow): def __init__(self): super(Application, self).__init__() self.setWindowIcon(QtGui.QIcon('icon.png')) I…
HumanAfterAll
  • 341
  • 1
  • 2
  • 6
18
votes
1 answer

AttributeError: 'Ui_MainWindow' object has no attribute 'setCentralWidget'

I am still working on the GUI for my Database and now i have a different error: Traceback (most recent call last): File "G:\Python\Database Kast Thuis\PyQt Test\MainMenu_ui.py", line 84, in ex = Ui_MainWindow() File…
That One
  • 581
  • 2
  • 6
  • 17
16
votes
2 answers

pyQt5 change MainWindow Flags

I use python 3.4 , pyQt5 and Qt designer (Winpython distribution). I like the idea of making guis by designer and importing them in python with setupUi. I'm able to show MainWindows and QDialogs. However, now I would like to set my MainWindow,…
polgia0
  • 347
  • 1
  • 3
  • 14
15
votes
1 answer

PyQt: Change GUI Layout after button is clicked

Okay, I am jumping from Tkinter to PyQt, because PyQt is just so much more advanced, and nicer to work with. BUT! I am having some troubles here. I am trying to change the GUI layout after I press one of my buttons on the main screen. I press the…
Tyrell
  • 896
  • 7
  • 15
  • 26
14
votes
6 answers

PyQt5 draggable frameless window

I found an example to set borders on a frameless window, however it's not draggable. How can I make a frameless window draggable? Especially if I can see an example it'll be awesome. Here is my example code(normally the code is longer, that's why…
GLHF
  • 3,835
  • 10
  • 38
  • 83
14
votes
3 answers

Can you add a toolbar to QDialog?

I'm working on a project that needs to call a modal window with a toolbar to do some work on some data before it's loaded. The reason I need the toolbar is the user has a few different possible options that can be combined. The obvious choice here…
John
  • 347
  • 1
  • 7
  • 14
13
votes
2 answers

How keep a QWidget always on top?

I have two buttons on my QMainWindow. One to btnShowKb and another btnHideKb. When i press btnShowKb it shows an QWidget. I want this QWidget always to be on top of all windows till I press btnHideKb. When its on top, I want both QWidget and…
Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
11
votes
2 answers

How to change color of QMainWindow borders and title bar?

The QMainWindow below is assigned a dark-gray background-color using QSS. I would also like to change the color of the borders and the color of the title bar. How to achieve control of the appearance of the QMainWindow borders and titlebar? I would…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
10
votes
4 answers

How to center a QDialog in QT?

I have this example code: QDialog *dialog = new QDialog(this); QPoint dialogPos = dialog->mapToGlobal(dialog->pos()); QPoint thisPos = mapToGlobal(this->pos()); dialog->exec(); But the Dialog is not centered on his parent. Thanks in…
Omar Murcia
  • 547
  • 2
  • 11
  • 26
10
votes
6 answers

MenuBar Not Showing for Simple QMainWindow Code, Qt Creator Mac OS

I have been having problems adding a menu item to the built in menu bar in a Qt desktop application. I copied the code provided in the QMainWindow class reference documentation for creating a menu to a very simple application. Unfortunately, it did…
joshf
  • 251
  • 1
  • 3
  • 6
1
2 3
34 35