"QT5 Development and examples" 11, Qpalette Palette use

Source: Internet
Author: User

I do this do not know why there are two features can not be displayed, and no error, I temporarily do not think of any good way = =


Achieve goals

Palette.h

/*** Book: "QT5 Development and examples" * Function: Implement palette usage qpalette* file: paletee.h* time: January 3, 2015 12:21:53* Author: cutter_point*/#ifndef palette_h# Define Palette_h#include <QDialog> #include <QComboBox> #include <QLabel> #include <QTextEdit> #include <QPushButton> #include <qlineedit>class palette:public qdialog{q_objectpublic:palette (Qwidget *  parent = 0);  ~palette ();  We divide this interface into two parts, the left and right//left interface created void Createctrlframe ();  Create void Createcontentframe () on the right side of the interface;  Color drop-down list box to enter the color of work void fillcolorlist (Qcombobox *);p rivate Slots://slot function, background color, foreground color showing void ShowWindow ();  void Showwindowtext ();  void Showbutton ();  void Showbuttontext ();      void Showbase ();p rivate:qframe *ctrlframe;  Color selection plate, left plate Qlabel *windowlabel;  Qcombobox *windowcombobox;  Qlabel *windowtextlabel;  Qcombobox *windowtextcombobox;  Qlabel *buttonlabel;  Qcombobox *buttoncombobox;  Qlabel *buttontextlabel;  Qcombobox *buttontextcombobox;  Qlabel *baselabel;  Qcombobox *basecombobox;   Qframe *contentframe; Specific displayThe panel, that is, the right half block Qlabel *label1;  Qcombobox *combobox1;  Qlabel *label2;  Qlineedit *lineedit2;  Qtextedit *textedit;  Qpushbutton *okbtn; Qpushbutton *cancelbtn;}; #endif//Palette_h

Palette.cpp

/*** Book: "QT5 Development and examples" * Function: Implement a specific palette * file: palette.h* time: January 3, 2015 12:20:05* Author: cutter_point*/#include "palette.h" #include <QHBoxLayout> #include <QVBoxLayout> #include <QGridLayout> #include <qtdebug>palette::    Palette (Qwidget *parent): Qdialog (parent) {//constructor createctrlframe ();   Constructs the Left interface Createcontentframe ();  Right Qhboxlayout *mainlayout = new Qhboxlayout (this);   Mainlayout->addwidget (Ctrlframe);    The left side of the interface is added into Mainlayout->addwidget (contentframe);  The right side of the interface is added into the}//to create the left color selector void Palette::createctrlframe () {ctrlframe = new Qframe;   Windowlabel = new Qlabel (tr ("Qpalette::window:"));  Display the background color selection windowcombobox = new Qcombobox;    Fillcolorlist (Windowcombobox);  Add all the colors to this dropdown box connect (windowcombobox, SIGNAL (activated (int)), this, SLOT (ShowWindow ()));   Windowtextlabel = new Qlabel (tr ("Qpalette::windowtext:"));  Display the foreground color selection windowtextcombobox = new Qcombobox;    Fillcolorlist (Windowtextcombobox); Add all the colors to this drop-down box connect (Windowtextcombobox, SIGNAL (activated (int)), this, SLOT (Showwindowtext ()));   buttonlabel = new Qlabel (tr ("Qpalette::button:"));  Display the foreground color selection buttoncombobox = new Qcombobox;    Fillcolorlist (Buttoncombobox);  Add all the colors to this dropdown box connect (buttoncombobox, SIGNAL (activated (int)), this, SLOT (Showbutton ()));   Buttontextlabel = new Qlabel (tr ("Qpalette::buttontext:"));  Display the foreground color selection buttontextcombobox = new Qcombobox;    Fillcolorlist (Buttontextcombobox);  Add all the colors to this dropdown box connect (buttontextcombobox, SIGNAL (activated (int)), this, SLOT (Showbuttontext ()));   Baselabel = new Qlabel (tr ("Qpalette::base:"));  Display the foreground color selection basecombobox = new Qcombobox;    Fillcolorlist (Basecombobox);  Add all the colors to this dropdown box connect (basecombobox, SIGNAL (activated (int)), this, SLOT (Showbase ()));   Grid layout Qgridlayout *mainlayout = new Qgridlayout (ctrlframe);   Layout of the left side of the interface mainlayout->setspacing (20);  The interval between vertical and horizontal mainlayout->addwidget (windowlabel, 0, 0);  Mainlayout->addwidget (Windowcombobox, 0, 1); Mainlayout->addwidget (WindoWtextlabel, 1, 0);  Mainlayout->addwidget (Windowtextcombobox, 1, 1);  Mainlayout->addwidget (buttonlabel, 2, 0);  Mainlayout->addwidget (Buttoncombobox, 2, 1);  Mainlayout->addwidget (Buttontextlabel, 3, 0);  Mainlayout->addwidget (Buttontextcombobox, 3, 1);  Mainlayout->addwidget (Baselabel, 4, 0); Mainlayout->addwidget (Basecombobox, 4, 1);}    Right window, display color void Palette::createcontentframe () {contentframe = new Qframe;  Create the right interface//Contentframe->setframestyle (Qframe::shadow_mask);    Label1 = new Qlabel (tr ("Please select one value:"));  Please don't spit my 中文版 comboBox1 = new Qcombobox;  Combobox1->additem (TR ("1"));  Combobox1->additem (TR ("2"));  Combobox1->additem (TR ("3"));    Label2 = new Qlabel (tr ("Please input String:"));  Please don't spit my 中文版 lineEdit2 = new Qlineedit;  TextEdit = new Qtextedit;  Grid layout Qgridlayout *toplayout = new Qgridlayout;  Toplayout->addwidget (label1, 0, 0);  Toplayout->addwidget (comboBox1, 0, 1); Toplayout->addwidget (Label2, 1, 0);  Toplayout->addwidget (LineEdit2, 1, 1);   Toplayout->addwidget (TextEdit, 2, 0, 1, 2);    Rows, columns, occupy rows, Occupy columns, and an alignment is not written out okbtn = new Qpushbutton (tr ("OK"));    Determine cancelbtn = new Qpushbutton (tr ("Cancel"));  Cancel Qhboxlayout *bottomlayout = new Qhboxlayout;    Bottomlayout->addstretch (1);  A spring Bottomlayout->addwidget (OKBTN);  Bottomlayout->addwidget (CANCELBTN);  Overall vertical layout qvboxlayout *mainlayout = new Qvboxlayout (contentframe);  Mainlayout->addlayout (toplayout); Mainlayout->addlayout (bottomlayout);} Show background color void Palette::showwindow ()//This does not know why the display does not come out!!!   Some say Windows does not support, I am also not very clear January 3, 2015 13:51:44{qstringlist colorlist = Qcolor::colornames ();   Get all the color sequences qcolor color = Qcolor (Colorlist[windowcombobox->currentindex ()));   Gets the currently selected ordinal number, getting the color Qpalette p = contentframe->palette ();   Get the Palette p.setcolor (Qpalette::window, color) on the right;     Modify the color of the corresponding position Contentframe->setpalette (p);   Apply the value of the palette to Contentframe->update (); Refresh the interface to get the display */* * QstringliSt ColorList = Qcolor::colornames ();    Qcolor color = Qcolor (Colorlist[cbbwindow->currentindex ()));    Qpalette p = Contentframe->palette ();    P.setcolor (Qpalette::window,color);   Contentframe->setpalette (P);   * */}//show foreground color void Palette::showwindowtext () {qstringlist colorlist = Qcolor::colornames ();   Get all the color sequences qcolor color = Qcolor (Colorlist[windowtextcombobox->currentindex ()));   Gets the currently selected ordinal number, getting the color Qpalette p = contentframe->palette ();   Get the Palette p.setcolor (qpalette::windowtext, color) on the right;     Modify the color of the corresponding position Contentframe->setpalette (p); Apply the value of the palette to the application//Contentframe->update ();} button background color void Palette::showbutton ()//This does not know why the display does not come out!!!   Some say Windows does not support, I am also not very clear January 3, 2015 13:51:44{qstringlist colorlist = Qcolor::colornames ();   Get all the color sequences qcolor color = Qcolor (Colorlist[buttoncombobox->currentindex ()));   Gets the currently selected ordinal number, getting the color Qpalette p = contentframe->palette ();   Get the Palette p.setcolor (Qpalette::button, color) on the right;   Modify the color of the corresponding position Contentframe->setpalette (p);  Apply the value of the palette to Contentframe->update ();}   The text on the button appears void Palette::showbuttontext () {qstringlist colorlist = Qcolor::colornames ();   Get all the color sequences qcolor color = Qcolor (Colorlist[buttontextcombobox->currentindex ()));   Gets the currently selected ordinal number, getting the color Qpalette p = contentframe->palette ();   Get the Palette p.setcolor (qpalette::buttontext, color) on the right;     Modify the color of the corresponding position Contentframe->setpalette (p); Apply the value of the palette to the application//Contentframe->update ();}   text box background color selection void Palette::showbase () {qstringlist colorlist = Qcolor::colornames ();   Get all the color sequences qcolor color = Qcolor (Colorlist[basecombobox->currentindex ()));   Gets the currently selected ordinal number, getting the color Qpalette p = contentframe->palette ();   Get the Palette p.setcolor (qpalette::base, color) on the right;     Modify the color of the corresponding position Contentframe->setpalette (p); Apply the value of the palette to the application//Contentframe->update ();}   Fillcolorlist used to insert the color void palette::fillcolorlist (Qcombobox *combobox) {qstringlist colorlist = Qcolor::colornames ();  Get all color names QString color;   foreach (color, colorlist)//loop out the values inside the ColorList {Qpixmap pix (qsize (70, 20));    This PIX acts as the icon for the display color Pix.fill (qcolor (color));    Fills the currently traversed color Combobox->additem (Qicon (PIX), NULL) for the PIX;     Insert the PIX as an icon in the Combobox->seticonsize (Qsize (70, 20));     Set the option to the same size as the PIX Combobox->setsizeadjustpolicy (qcombobox::adjusttocontents); Sets the size of the drop-down box to match the content size}}palette::~palette () {}

Implementation results:





There is also I found that upload things or there is a total space limit, that is, upload more, space size is not enough, the pit dad is I actually only 60M, I am hehe, this is really Jin Gui, I might as well make a network disk





"QT5 Development and examples" 11, Qpalette Palette use

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.