Differences and choices between MainWindow, Qwidget and Qdialog (reproduced)

Source: Internet
Author: User
Tags emit

The Qapplication class is used to manage application-scoped resources whose constructors require the argc and argv of the main function as arguments.

Widgets are not visible when they are created, and widgets can accommodate other widgets.

The widgets in QT emit signal when there is a user behavior or state change. Signal can be connected to the slot function (connect) so that when signal is emit, the corresponding slot function is automatically called.

The constructor for the Qwidget class requires a qwidget * pointer as a parameter that represents its parent widget (the default value is 0, i.e. no parent widget exists). When the parent widget is deleted, QT automatically deletes all of its child widgets.

There are three types of layout manager classes in QT: Qhboxlayout, Qvboxlayout, and Qgridlayout. The basic mode is to add widgets to layout, which automatically takes over the widget's size and position.

The program's default display style can be changed by the-style parameter when starting the QT program.

Sub-Class Dialog

The base class for all dialog in Qt is Qdialog. Qdialog derived from Qwidget.

All classes in QT that define a signal or slot, use the Q_object macro at the beginning of their class definition. The signal keyword in QT is actually a macro definition, similarly, the Slots keyword is also a macro definition.

The QOBJECT::TR () function converts the input string to another language (internationalization). It is a good practice to use internationalized languages for all user-visible strings.

Buddy: Two Widge A and B, if a has a shortcut key, when the user presses the shortcut key, the program's input focus automatically transferred to B, then said B is a Buddy.

Qwidget::close () is a slot whose default behavior is to make the corresponding widget invisible, but does not delete the widget.

Layout can include widgets and other layout. A very complex dialog can be constructed by nesting using Qhboxlayout, Qvboxlayout, and Qgridlayout. It is worth noting that the layout manager class is not part of the widget. In fact, it derives from Qlayout, and Qlayout is derived with Qobject.

Qwidget::sizehint () returns the ideal size () of a widget.

The Emit keyword is QT-specific and is used to produce signal.

MoC (Meta-object-compiler): For all classes that use Q_object macros, they need to be processed by the MOC at compile time, otherwise there will be a connection error, the solution to the error is simple, re-executing qmake to update makefile, and then recompile.

Signal&slot mechanism is the foundation of QT

Slots are almost identical to ordinary C + + class member functions, which can be virtual, can be overloaded, be public, protected, or private, and can also be called directly by other member functions.

The association between signal and slots can be a pair of one or one-to-many, many-to-one. Signal and signal can also be associated, the difference between this situation and signal-slot is that when the first signal is emit, the second signal also do not emit. You can call disconnect () to disassociate the signal from the slot, which is typically rarely required to display the call disconnect (), because QT automatically removes the associated association when the object is deleted.

Differences and choices between MainWindow, Qwidget and Qdialog (reproduced)

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.