QT Window widgets and sub-parts

Source: Internet
Author: User

The Qwidget class is the base class for all user-interface objects, called the Base window part.

#include <QApplication> #include <QLabel> #include <qwidget>int main (int argc, char *argv[]) {    Qapplication A (argc, argv);        New Qwidget class object, the default parent parameter is 0, so it is a window        qwidget *widget = new Qwidget ();        Set the window caption        widget->setwindowtitle (qobject::tr ("I Am the Widget"));        New Qlabel object, the default parent parameter is 0, so it is a window        qlabel *label = new Qlabel ();        Label->setwindowtitle (Qobject::tr ("I am a label"));        Set the information to be displayed        Label->settext (qobject::tr ("Label: I am a Window"));        Change the size of the part so that it can show the complete content        label->resize (+);        LABEL2 specifies that the parent window is a widget, so it is not a window        qlabel *label2 = new Qlabel (widget);        Label2->settext (Qobject::tr ("Label2: I'm not a standalone window, just a widget's subassembly");        Label2->resize (+);        Display on the screen        label->show ();        Widget->show ();    return a.exec ();}

1. In QT, parts that are not embedded in other parts are called Windows, and the general window has borders and title bars, just like widgets and labels in a program. A window is a part that has no parent part, and all is called a top-level part. Its relative non-window part, also known as a child part.

2. There are drawbacks to this simple statement, such as: Qdialog is a window is beyond doubt, but in the use of dialog boxes for which the parent window is also normal;

3. I read the last two lines of code delete label; Delete widget, but after adding these two sentences, the result will be displayed in the background and will not appear on the desktop;

4. In the program, the label does not have a parent window, and Label2 in the widget, the widget is its parent window. The program uses new to allocate space for the Label2, but does not use Delete to release it because the child objects are automatically destroyed when the parent object is destroyed in Qt.

QT Window widgets and sub-parts

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.