Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - What exactly is QWidget

Tags:

c++

qt

qwidget

In the C++ GUI Programming with Qt 4 book, it mentions in an example in the first chapter that QWidget serves as the application's main window.

And, on the Qt Reference Documentation: http://doc.qt.io/qt-4.8/qwidget.html there is plenty of information about QWidget.

But, what is the baseline? What does QWidget mainly do? When should I think about it?

like image 311
Simplicity Avatar asked Apr 07 '11 19:04

Simplicity


People also ask

What is the difference between QMainWindow and QWidget?

A QDialog is based on QWidget , but designed to be shown as a window. It will always appear in a window, and has functions to make it work well with common buttons on dialogs (accept, reject, etc.). QMainWindow is designed around common needs for a main window to have.

Is QWidget a QObject?

All Qt widgets inherit QObject. The convenience function isWidgetType() returns whether an object is actually a widget. It is much faster than qobject_cast<QWidget *>(obj) or obj->inherits("QWidget"). Some QObject functions, e.g. children(), return a QObjectList.

What is QWidget * parent?

The tree-like organization of QWidgets (and in fact of any QObjects ) is part of the memory management strategy used within the Qt-Framework. Assigning a QObject to a parent means that ownership of the child object is transferred to the parent object. If the parent is deleted, all its children are also deleted.

What is QMainWindow in Qt?

Qt Main Window Framework A main window provides a framework for building an application's user interface. Qt has QMainWindow and its related classes for main window management. QMainWindow has its own layout to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar.


2 Answers

One way to think about it is any object that knows how to display itself on the screen is a QWidget (in particular, some subclass of QWidget).

There are some objects like QPicture that represent an image, but a QPicture by itself doesn't know how to put itself on the screen. You usually need to use it in combination with a QLabel for instance (which is a kind of QWidget).

like image 149
Greg Hewgill Avatar answered Sep 17 '22 00:09

Greg Hewgill


It is an abstract of window objects. Every visible/invisible Qt window-related object inherits from QWidget.

Just consider a vehicle, it is the abstract of cars, trucks and other stuffs.

like image 28
xis Avatar answered Sep 18 '22 00:09

xis