Qt learning-QQ chat list qtoolbox class

Source: Internet
Author: User

You can design the contact list for the drawer effect displayed in qtoolbox.

The following shows the main interface of QQ, a chat software.

The header file mainly defines the contact qtoolbutton:

#include <QToolBox>#include <QToolButton>class Drawer : public QToolBox{    Q_OBJECTpublic:    Drawer(QWidget *parent=0,Qt::WindowFlags f=0);private:    QToolButton *toolBtn1_1;    QToolButton *toolBtn1_2;    QToolButton *toolBtn1_3;    QToolButton *toolBtn1_4;    QToolButton *toolBtn1_5;    QToolButton *toolBtn2_1;    QToolButton *toolBtn2_2;    QToolButton *toolBtn3_1;    QToolButton *toolBtn3_2;};

Add the contact to three qtoolboxes in the source file.

# Include "drawer. H "# include <qgroupbox> # include <qvboxlayout> drawer: drawer (qwidget * parent, QT: windowflags F): qtoolbox (parent, 0) {setwindowtitle (TR ("My QQ ")); // ********************************* toolbtn1_1 = new qtoolbutton; toolbtn1_1-> settext (TR ("Zhang San"); toolbtn1_1-> seticon (qpixmap ("Res/11.bmp"); toolbtn1_1-> seticonsize (qpixmap ("Res/11.bmp "). size (); toolbtn1_1-> setautoraise (true); toolbtn1_1-> settoolbuttonstyle (QT: toolbuttontextbesideicon); toolbtn1_2 = new qtoolbutton; toolbtn1_2-> settext (TR ("Li Si"); toolbtn1_2-> seticon (qpixmap ("Res/12.bmp"); toolbtn1_2-> seticonsize (qpixmap ("Res/BMP "). size (); toolbtn1_2-> setautoraise (true); toolbtn1_2-> settoolbuttonstyle (QT: toolbuttontextbesideicon); toolbtn1_3 = new qtoolbutton; toolbtn1_3-> settext (TR (""); toolbtn1_3-> seticon (qpixmap ("Res/13.bmp"); toolbtn1_3-> seticonsize (qpixmap ("Res/13.bmp "). size (); toolbtn1_3-> setautoraise (true); toolbtn1_3-> settoolbuttonstyle (QT: toolbuttontextbesideicon); toolbtn1_4 = new qtoolbutton; toolbtn1_4-> settext (TR ("Xiao Zhao"); toolbtn1_4-> seticon (qpixmap ("Res/14.bmp"); toolbtn1_4-> seticonsize (qpixmap ("Res/14.bmp "). size (); toolbtn1_4-> setautoraise (true); toolbtn1_4-> settoolbuttonstyle (QT: toolbuttontextbesideicon); toolbtn1_5 = new qtoolbutton; toolbtn1_5-> settext (TR ("sun"); toolbtn1_5-> seticon (qpixmap ("Res/15.bmp"); toolbtn1_5-> seticonsize (qpixmap ("Res/15.bmp "). size (); toolbtn1_5-> setautoraise (true); toolbtn1_5-> settoolbuttonstyle (QT: toolbuttontextbesideicon ); // **************** add my friend ******************** qgroupbox * groupbox1 = new qgroupbox; qvboxlayout * layout1 = new qvboxlayout (groupbox1); layout1-> setmargin (10); layout1-> setalignment (QT: alignhcenter); layout1-> addwidget (batch ); layout1-> addwidget (latency); layout1-> addwidget (toolbtn1_3); layout1-> addwidget (latency); layout1-> addwidget (latency); layout1-> addstretch (); // ************************************* toolbtn2_1 = new qtoolbutton; toolbtn2_1-> settext (TR ("John"); toolbtn2_1-> seticon (qpixmap ("Res/21.bmp"); toolbtn2_1-> seticonsize (qpixmap ("Res/21.bmp "). size (); toolbtn2_1-> setautoraise (true); toolbtn2_1-> settoolbuttonstyle (QT: toolbuttontextbesideicon); toolbtn2_2 = new qtoolbutton; toolbtn2_2-> settext (TR ("Xiao Zhang"); toolbtn2_2-> seticon (qpixmap ("Res/22.bmp"); toolbtn2_2-> seticonsize (qpixmap ("Res/22.bmp "). size (); toolbtn2_2-> setautoraise (true); toolbtn2_2-> settoolbuttonstyle (QT: toolbuttontextbesideicon ); // *************** Add a stranger ********************* qgroupbox * groupbox2 = new qgroupbox; qvboxlayout * layout2 = new qvboxlayout (groupbox2); layout2-> setmargin (10); layout2-> setalignment (QT: alignhcenter); layout2-> addwidget (batch ); layout2-> addwidget (toolbtn2_2); layout2-> addstretch (); // ************************************ toolbtn3_1 = new qtoolbutton; toolbtn3_1-> settext (TR ("John"); toolbtn3_1-> seticon (qpixmap ("Res/31.bmp"); toolbtn3_1-> seticonsize (qpixmap ("Res/31.bmp "). size (); toolbtn3_1-> setautoraise (true); toolbtn3_1-> settoolbuttonstyle (QT: toolbuttontextbesideicon); toolbtn3_2 = new qtoolbutton; toolbtn3_2-> settext (TR ("Xiao Zhang"); toolbtn3_2-> seticon (qpixmap ("Res/32.bmp"); toolbtn3_2-> seticonsize (qpixmap ("Res/32.bmp "). size (); toolbtn3_2-> setautoraise (true); toolbtn3_2-> settoolbuttonstyle (QT: toolbuttontextbesideicon ); // **************** Add a blacklist ******************** qgroupbox * groupbox3 = new qgroupbox; qvboxlayout * layout3 = new qvboxlayout (groupbox3); layout3-> setmargin (10); layout3-> setalignment (QT: alignhcenter); layout3-> addwidget (release ); layout3-> addwidget (toolbtn3_2); layout3-> addstretch (); // *************** add to the main window ******************* this-> additem (qwidget *) groupbox1, TR ("my friends"); this-> additem (qwidget *) groupbox2, TR ("Stranger"); this-> additem (qwidget *) groupbox3, TR ("Blacklist "));}

Find the image and put it in the res folder.

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.