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