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

Changing between Widgets in QMainWindows central Widget

I have a main Window derived form QMainWindow that may show different Widgets, depending on the task at hand. I created a simplified example below: from PyQt4.QtCore import * from PyQt4.QtGui import * import sys class MainWindow(QMainWindow): …
MichaelA
  • 1,866
  • 2
  • 23
  • 38
3
votes
2 answers

What to use with Qt for independent windows: a QDialog, a QWindow or a QMainWindow?

I am making my first steps with Qt. As an exercise, I am writing a GUI for a many-core processor, and individual cores are shown in a separate window. From this window, there may be several copies, with their independent life, including menus,…
katang
  • 2,474
  • 5
  • 24
  • 48
3
votes
1 answer

How to iterate over all widgets in a window?

I know that for a QObject, there is a way to find all QObjects that are considered children - but I don't know if that means I would be able to find all widgets in the MainWindow. Plus, I don't want to find any non-widgets. I ask because I'm trying…
SaburoutaMishima
  • 269
  • 4
  • 15
3
votes
2 answers

How do I add a scroll bar to a QMainWindow that has one central widget?

How can I add a scroll bar to a QMainWindow, when this QMainWindow contains just one central widget, which is bigger than the QMainWindow size? So that the scroll bar can be used to see different parts of this central widget.
Ahmad
  • 12,886
  • 30
  • 93
  • 146
3
votes
3 answers

How to display text in main window?

I'm new to Qt and I'm having a hard time finding a simple example illustrating how to display some text on the main window. For example, I just want to save some text in a string and display the contents on the main window. I thought to do something…
the_prole
  • 8,275
  • 16
  • 78
  • 163
3
votes
1 answer

Qt Framework, PyQt5 and AttributeError: 'MyApp' object has no attribute 'myAttribute'

Last week I started to learn Python and I developed some command line apps. Now I would like to develop apps with GUI. I searched in internet and I found a project that fits my needs: Qt Project (http://qt-project.org) and PyQt…
Andrea Venanzi
  • 230
  • 5
  • 15
3
votes
0 answers

PyQt is slow in handling a large number of objects

I present here a simple pyqt code, but I developed my whole design and algo upon this. The problem, is that PyQt is unable to manage a large number of objects when created. This is simple code for drawing many rectangles inside a big one. And it has…
phaigeim
  • 729
  • 13
  • 34
3
votes
2 answers

Widgets are not shown in basic Qt application (QMainWindow)

I am new to Qt and I am doing some practice with simple examples. I just wanted to test my knowledge with a simple application, by coding, in which user types a text in QLineEdit widget and the text will be shown in QLabel. There is no need for it…
ukll
  • 204
  • 2
  • 12
3
votes
1 answer

Run function when push button is clicked

I am using the Qt add in for visual studio. Now I made a simple push button using Qt designer, and I want to use that push button so that it runs a function with a certain inputparameter when it is pressed, and then displays the result that is…
dreamer
  • 1,192
  • 5
  • 20
  • 42
3
votes
3 answers

How can I set text of label when a function is running?

I want to set the text of a label on main window when a function in code is running. But the label does not change until the function ends. for (int i = 0; i < files.size(); ++i) { ui->label->setText(files[i]); myfoo(); }
user2362956
3
votes
2 answers

Python: How Close (or exit) Python Process After QMainWindow Dialog is closed

There are two .py files placed in a same folder: dialog_01.py and dialog_02.py Both files are copy of each other. Both build a simple QMainWindow dialog window with two buttons: 'Ok' and 'Cancel'. Clicking 'Ok' button closes a currently opened…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
3
votes
2 answers

How to import mainwindow (.ui file) using PySide

I'm doing a python project and design its interface using PySide. The problem is how can I import mainwindow (.ui file) from Qt Designer using PySide. My class is inherited from QtGui.QMainWindow. Thank you for your answer. ^^
Pandarian Ld
  • 727
  • 3
  • 13
  • 25
3
votes
1 answer

How to paint in a QMainWindow?

I have an extremely strange behaviour of a QPainter. In my 'MainWindow::paintEvent()' it works correctly: QPainter painter(this); qDebug() << "painter adress in paintEvent: " << (&painter); painter.setBrush(Qt::red); painter.drawRect(100, 100, 100,…
Bianfable
  • 237
  • 5
  • 13
3
votes
1 answer

Qt: HBoxLayout - stop MainWindow from resizing to contents

It seems most people are asking how to make their QMainWindow resize to its contents - I have the opposite problem, my MainWindow does resize and I don't know why. When I set my QLabel to a longer text, my mainwindow suddenly gets bigger, and I…
The Compiler
  • 11,126
  • 4
  • 40
  • 54
3
votes
2 answers

(Py)Qt: Spacing in QHBoxLayout shows centralwidget's background, not parent's

Consider the following example code: from PyQt5.QtWidgets import (QApplication, QHBoxLayout, QLabel, QWidget, QMainWindow, QVBoxLayout, QTextEdit) class MainWindow(QMainWindow): def __init__(self): …
The Compiler
  • 11,126
  • 4
  • 40
  • 54