This example adds the implementation of the scroll bar and controls the style of the component through stylesheet.
The main code is as follows:
# Include "mainframe. H "# include <iostream> # include <qtgui/qicon> mainframe: mainframe () {widget = NULL; setgeometry (0, 0, 500,300); this-> setautofillbackground (true ); qpalette palette; palette. setbrush (qpalette: Background, qbrush (qpixmap ("/workspace/image/test1.jpg"); this-> setpalette (palette); qpalette palette2; palette2.setbrush (qpalette :: background, qbrush (qpixmap ("/workspace/image/test2.jpg"); q Pushbutton * button_add = new qpushbutton ("addbutton", this); qpushbutton * button_del = new handle ("delbutton", this); button_add-> setgeometry (20, 20 ); button_add-> setobjectname ("button_add"); button_add-> setstylesheet ("qpushbutton # button_add {color: red; Background: URL (/workspace/image/test2.jpg); font-size: 20px}; "); button_del-> setgeometry (,); button_del-> setobjectname (" button_del "); Button_del-> setstylesheet ("qpushbutton # button_del {color: red; Background: URL (/workspace/image/test2.jpg); font-size: 20px};"); Connect (button_add, signal (clicked (), this, slot (addbutton (); Connect (button_del, signal (clicked (), this, slot (delbutton ())); scrollarea = new qscrollarea (this); scrollarea-> setgeometry (20,100,460,180);} mainframe ::~ Mainframe () {} void mainframe: addbutton () {STD: cout <"addbutton clicked! "<STD: Endl; If (widget! = NULL) {widget-> hide (); widget = NULL;} widget = new qwidget (); widget-> setgeometry (0, 0, 460,400 ); qpushbutton * button1 = new qpushbutton ("aaaaaaaaaa", widget); button1-> setobjectname ("button_extra"); qpushbutton * button2 = new qpushbutton ("plugin", widget ); button2-> setobjectname ("button_extra"); qpushbutton * button3 = new qpushbutton ("cccccccccc", widget); button3-> setobjectname ("button_extra"); qpushbutt On * button4 = new qpushbutton ("dddddddddd", widget); button4-> setobjectname ("button_extra"); qpushbutton * button5 = new qpushbutton ("eeeeeeeeeeee", widget ); button5-> setobjectname ("button_extra"); widget-> setobjectname ("widget"); button1-> setgeometry (20,100,200,); button2-> setgeometry (, 50 ); button3-> setgeometry (20,190,200, 50); button4-> setgeometry (20,250,200, 50); button5-> setgeometry (20,310,200, 50); scrollarea-> setwidget (widget); widget-> setstylesheet ("qpushbutton # button_extra {color: red; Background: URL (/workspace/image/test3.jpg ); font-size: 20px} qwidget # widget {color: red; Background: URL (/workspace/image/test1.jpg); font-size: 20px }"); // note that the style widgets of button_extra and Widget are set here-> show ();} void mainframe: delbutton () {STD: cout <"delbutton clicked! "<STD: Endl; If (widget! = NULL) {widget-> hide (); widget = NULL ;}}
Running result:
(--------- End --------)