Questions tagged [qapplication]

The QApplication class is part of the Qt C++ classes manages the GUI application's control flow and main settings.

The QApplication class manages the application's control flow and main settings. QApplication specializes QGuiApplication with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization.

For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time.

Some GUI applications provide a special batch mode ie. provide command line arguments for executing tasks without manual intervention. In such non-GUI mode, it is often sufficient to instantiate a plain QCoreApplication to avoid unnecessarily initializing resources needed for a graphical user interface.

The QApplication object is accessible through the instance() function that returns a pointer equivalent to the global qApp pointer.

QApplication's main areas of responsibility are:

  • It initializes the application with the user's desktop settings such as palette(), font() and doubleClickInterval(). It keeps track of these properties in case the user changes the desktop globally, for example through some kind of control panel.
  • It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. By using sendEvent() and postEvent() you can send your own events to widgets.
  • It parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details.
  • It defines the application's look and feel, which is encapsulated in a QStyle object. This can be changed at runtime with setStyle().
  • It specifies how the application is to allocate colors. See setColorSpec() for details.
  • It provides localization of strings that are visible to the user via translate().
  • It provides some magical objects like the desktop() and the clipboard().
  • It knows about the application's windows. You can ask which widget is at a certain position using widgetAt(), get a list of topLevelWidgets() and closeAllWindows(), etc.
  • It manages the application's mouse cursor handling, see setOverrideCursor().
160 questions
0
votes
1 answer

PyQt4:different views in centralWidget. Best practice SW-Architecture

In my program I want to define different views to show my data. In my first tries all views were defined in on class (QtGui.QWidget). However since the code for the views started to become longer and I also want to add interactive features, I want…
BerndGit
  • 1,530
  • 3
  • 18
  • 47
0
votes
1 answer

Simple Input Dialog in PyQt4

I am writing a program which checks if user is root. If not an input dialog shows up for password. I have done this earlier too (inside some class) but lost the file somewhere. if os.name == 'posix': if not os.getuid() == 0: input, ok =…
sundar_ima
  • 3,604
  • 8
  • 33
  • 52
0
votes
0 answers

qapplication multiple inheritance

I want to create a class that inherits from two classes, one of them being QApplication. class TheApp : public QApplication, public MyApp { public: TheApp(int argc, char *argv[]) : QApplication(argc,argv), MyApp(argc,argv) {} }; int…
0
votes
0 answers

QPixmap: Must construct a QApplication before a QPaintDevice

I have a code which works in python console of QGIS. I am trying to work in an IDE but it does not work. I have changed it in different ways but it still returns: QPixmap: Must construct a QApplication before a QPaintDevice my code is: import…
msc87
  • 943
  • 3
  • 17
  • 39
-1
votes
0 answers

Stylesheet(QSS) not work when I use qApp.setStyleSheet(qss)

// MyDialog.h // #pragma once #include #include #include class MyDialog : public QProgressDialog { Q_OBJECT public: explicit MyDialog(const QString &text, QWidget *parent = nullptr) :…
Paul
  • 1
  • 2
-1
votes
1 answer

python QApplication freezes and does not close while another thread is running

In the main file i run a Qapplication in the main thread (that starts with no problem) and a method on a separate thread , called backupGiornaliero. When I try to close the application via the X button of the user interface of the app or by a button…
Emanuele
  • 1
  • 3
-1
votes
1 answer

Undefined variable 'QApplication' & Undefined variable 'QDialog'

My problem is after installing Python and PyQt5 in vs code, when I run the code he show me this problem: Undefined variable 'QApplication' Undefined variable 'QDialog' But I found a solution here No name 'QApplication' in module 'PyQt5.QtWidgets'…
-1
votes
2 answers

QApplication in a non-main thread of second process with pyQt4: is this code legal, and if not, why does it work?

My collaborators and I have programed an integrated development environment (IDE) in python 2.7 and pyQt4 that has been working perfectly for more than ten years. I have now to port it to pyqt5 and I encounter several problems. This post is related…
-3
votes
1 answer

catch that new QApplication failed and try something else

I have two programs. One call SelectScreen and another called RadioPanel. SelectScreen sends a message to RadioPanel telling it what screen its supposed to display the gui on. RadioPanel uses setenv("DISPLAY", myHostslist[hostId].c_str(),true); to…
skalloz
  • 1
  • 1
-3
votes
1 answer

Two Buttons in Qt Gui

I've written a program with different functions in Qt. Now I want to make a Gui. For example I have two buttons, button1 and button2. I open the application, i see button1 first. Then I click button1, it executes its function (like "start") and…
pjs
  • 39
  • 1
  • 4
1 2 3
10
11