Qt Study Notes (2) layout manager & signals and slots (Introduction)

Source: Internet
Author: User

In the previous sectionProgramAdd small applications. The layout manager and signal and slot are mainly used. Here I just want to briefly introduce it ~~ With the subsequent in-depth research, we will introduce it in detail ~

I. layout manager

 
# Include <qtgui> int main (INT argc, char * argv []) {qapplication A (argc, argv); qtextcodec: setcodecfortr (qtextcodec: codecforlocale ()); qwidget * pwidget = new qwidget; // create a new widget qlabel label (pwidget); // label's parent is pwidget // qlabel * label = new qlabel (pwidget ); label. settext (qobject: TR ("Hello World"); // set the label text qpushbutton closebtn (pwidget); closebtn. settext (qobject: TR ("close"); qvboxlayout layout; // vertical layout. addwidget (& label); // Add part layout. addwidget (& closebtn); pwidget-> setlayout (& layout); // layout the application to pwidget-> show (); Return a.exe C ();}

Here we define a vertical layout manager layout. After each layout manager is designed, qwidget must be called::Setlayout(Qlayout*Layout). Otherwise, the interface is not displayed normally.

Because the starting coordinates, width, and height of the QT component you define are consistent.

We can testCodeVerified.

 
Qdebug () <closebtn. POs () <label. POs (); qdebug () <closebtn. width () <closebtn. height (); qdebug () <label. width () <label. height ();

Obviously, we need to add # include <qdebug> in the file header, as shown in figure.

Qdebug () is often used for debugging information output.

/*

Thanks to dbzhang800 for his point of view

It is indeed a top-level layout that must be set to the application widget.

Parent_layout-> addlayout (child_layout );

For the child layout, we can call addlayout to add it to the parent layout.

*/

The normal execution of the program is as follows:

We add the signal and slot on the basis of the above, and add

 
Qobject: connect (& closebtn, signal (clicked (), pwidget, slot (close ()));

The result is that when we click the close button of the window, the whole window will be closed.

Qobject: connect (const qobject * asender, const char * asignal, const char * amember, QT: connectiontype Atype)

Since clicked () and close () have QT definitions, we do not need to implement them. Signal () and slot () are two macros defined by QT, they return the string of their parameters (const char *)

Add the program hereSource codeDownload link: http://download.csdn.net/detail/fzu_dianzi/3703745

The above are purely personal study notes. If anything goes wrong, I hope to raise it. We hope to study and make progress together. My email address is: xzy@yingzhi8.com

 
 

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.