Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Designer: Changing the base class of a window

Tags:

I already created a second window for my application in the Qt Designer. I read that a QMainWindow would be the wrong class for the second window (which basically should only be some kind of dialog), so I would like to change the base class.

My Question(s) are:

  1. Is there a way to change the base class without creating a new window and copying my code into the new files?
  2. Can somebody please explain when to use QMainWindow, QDialog and QWidget? I did not found good explanations for the differences between these three base classes in Qt.
like image 701
mario.schlipf Avatar asked Jul 11 '13 23:07

mario.schlipf


People also ask

What is base class in Qt?

The QObject class is the base class of all Qt objects. QObject is the heart of the Qt object model providing support for signals, slots, and the meta object system. The QPaintDevice class is the base class of objects that can be painted on with QPainter.

How do you set auto resize GUI in Qt depending on the screen size?

In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout. Then your QFormLayout will automatically resize. Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget!

What is QWidget class window?

The QWidget class is the base class of all user interface objects.


1 Answers

  1. To change the base class you could only change the : public QMainWindow to : public QWidget (or vice-versa) in the header-file and of course also the *.cpp.

  2. Basically all three are QWidgets, each with special functionality or for specific purposes. As far as I know the QMainWindow has toolbars, menubars and docks, a QDialog will always be shown as a seperate window (e.g. blocking, non-blocking, etc.) and the QWidget itself is the base-class. I.e. QPushButton, QCombobox are derived from QWidget too. In my opinion it would be better to use only one QMainWindow since it should be a central point of interaction/navigation for the user

EDIT: I forgot to mention that also the UI-file has to be changed, i.e. by using a text-editor, change the line (4th row I think)

<widget class="QMainWindow" name="YourClassName"> 

to

<widget class="QWidget" name"YourClassName"> 

and remove all QMainWindows related parts (menubar, toolbar, ...), and the enclosing tag for the central widget.

Thanks to alexisdm for the tip.

like image 119
Robert Avatar answered Sep 28 '22 05:09

Robert