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
4
votes
1 answer

QDockWidget::restoreGeometry not working correctly when QMainWindow is maximized

I have a number of QDockWidgets, all docked in a single QMainWindow. I have overridden the showEvent, and after passing the event on to the base class I am restoring the dock widget's geometry void DockWidget::showEvent(QShowEvent* ev) { …
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
4
votes
5 answers

Qt add menuBar, menus, and sub menus to QMainWindow

I have a hard time adding menu Bar, menus and sub menus to Qt QMainWindow programmatically. The following code produces an error: QWidget::setLayout: Attempting to set QLayout "" on QMainWindow "", which already has a layout Notes : *.The main…
Joseph Ali
  • 345
  • 1
  • 5
  • 11
4
votes
3 answers

PyQt having a status bar & menu bar QWidget

I am trying to create a PyQt application that has both status bar and a menu bar with other Widgets in the window. Below is the code which I managed to get it run with class QtGui.QMainWindow method. But as I intend to add further features, I…
SamAct
  • 529
  • 4
  • 23
4
votes
2 answers

Qt: resizable and movable main window without title bar

I need draw a Qt-window without the title bar. Generally this can be easy by just setting the CustomizeWindowHint window attribute. But then window has fixed size and position. I need a movable and resizable window. This post shows how to move the…
frans
  • 8,868
  • 11
  • 58
  • 132
4
votes
1 answer

How to keep my QMainWindow always inside of the desktop?

I want to keep my QMainWindow always inside of the desktop, so I add the implementation for QMainWindow::moveEvent : void MainWindow::moveEvent(QMoveEvent *ev) { if(ev->pos().x() < 0) setGeometry(0, ev->oldPos().y(), width(), height()); } But…
aviit
  • 1,957
  • 1
  • 27
  • 50
4
votes
3 answers

Resize QMainWindow to minimal size after content of layout changes

I'm using a subclass of QMainWindow, in which I declared a central widget. This widget contains, among other things, a QGridLayout, which holds a set of buttons. The amount of buttons can grow or shrink, depending on the user's input. The spacing is…
Steffen
  • 3,999
  • 1
  • 23
  • 30
4
votes
1 answer

Qt: why adding layout to MainWindow (by code) didn't work but adding as CentralWidget worked?

I have coded a QWidget MyWidget and I wanted to add two MyWidget with QVBoxLayout in the MainWindow class (the same MainWindow which is provided default when we open Qt Creator). So, what I did was, in the constructor of MainWindow, I took two…
Shakib Ahmed
  • 781
  • 2
  • 10
  • 24
4
votes
0 answers

How to show clickable QFrame without loosing focus from main window?

Finally I am able to create a chrome like tab in Qt/PyQt QMainWindow. After unsuccessfully trying to port this Qt C++ non client area painting code, I revise my thinking to be this way : trick visually by displaying a free floating QFrame that get…
swdev
  • 4,997
  • 8
  • 64
  • 106
4
votes
2 answers

Qt Splash Screen not showing

I have this code, I want it to show a splash screen since it will be bigger, having had made a kind of timer so it is possible to see the splash screen working. The problem is I don't see the splash screen, but the code will be running while the…
vitimiti
  • 77
  • 1
  • 8
4
votes
3 answers

Set background of QMainWindow central widget

Using Qt 4.8.4 on Windows 7 (MSVC 2010) I have a standard QMainWindow in my app with a toolbar. I want the toolbar to stay grey, but the central widget should have a white background. Calling centralWidget->setStyleSheet("background-color: white;")…
Batox
  • 574
  • 1
  • 4
  • 16
4
votes
1 answer

QMainWindow::showMaximized() Doesn't Update Size

I'm trying to create a QMainWindow to encapsulate a QGraphicsView that I'm putting in it. I want it to start out maximized, so I do this: QMainWindow *mainWindow = new…
K. Barresi
  • 1,275
  • 1
  • 21
  • 46
4
votes
1 answer

How to add a widget to QMainWindow layout?

I'm using the code below to add a QPushButton to a ui: QPushButton *mine[PlayForm->horizontal][PlayForm->vertical]; for(int i=0; ihorizontal; i++) { for(int j=0; jvertical; j++) { QWidget…
Khosi
  • 183
  • 1
  • 3
  • 9
4
votes
2 answers

Qt4: Hide minor widgets while maintaining size of central widget

I have a QMainWindow with a main "display" widget, and several minor widgets. I'd like the ability to toggle the minor widgets on/off when the mouse enters or leaves the window. I can achieve this basic functionality by implementing enterEvent and…
ChrisB
  • 4,628
  • 7
  • 29
  • 41
4
votes
2 answers

store variables from a qdialog to use in qmainwindow

I've created a dialog.h, dialog.cpp and a dialog.ui, and I have qlineedit in the dialog, as well as ok and cancel button, and i want to store those linedit information to use in a mainwindow in a different file. here's my dialog code. #include…
SamuelNLP
  • 4,038
  • 9
  • 59
  • 102
4
votes
1 answer

PyQt: Accesing Main Window's Data from a dialog?

So, I'm using Python and PyQt. I have a Main Window that contains a QTableWidget, and a dialog that opens modally and has some QLineEdit widgets... All right so far, but I have 2 problems: When the dialog opens, my Main Window freezes, and I don't…
Antoni4040
  • 2,297
  • 11
  • 44
  • 56