#-*-Coding: UTF-8 -*-
From pyqt4.qtgui import *
From pyqt4.qtcore import *
Import sys
Qtextcodec. setcodecfortr (qtextcodec. codecforname ("utf8 "))
Class palette (qdialog ):
Def _ init _ (self, parent = none ):
Super (palette, self). _ init _ (parent)
Self. setwindowtitle (self. tr ("qpalette dialog box "))
Mainlayout = qhboxlayout (Self)
Self. ctrlframe = qframe ()
Self. contentframe = qframe ()
Self. contentframe. setautofillbackground (true)
Self. createctrlframe ()
Self. createcontentframe ()
Mainlayout. addwidget (self. ctrlframe)
Mainlayout. addwidget (self. contentframe)
Def createctrlframe (Self ):
Label1 = qlabel ("qpalette. Window ")
Self. windowcombobox = qcombobox ()
Label2 = qlabel ("qpalette. windowtext ")
Self. windowtextcombobox = qcombobox ()
Label3 = qlabel ("qpalette. Button ")
Self. buttoncombobox = qcombobox ()
Label4 = qlabel ("qpalette. buttontext ")
Self. buttontextcombobox = qcombobox ()
Label5 = qlabel ("qpalette. Base ")
Self. basecombobox = qcombobox ()
Self. fillcolorlist (self. windowcombobox)
Self. fillcolorlist (self. windowtextcombobox)
Self. fillcolorlist (self. buttoncombobox)
Self. fillcolorlist (self. buttontextcombobox)
Self. fillcolorlist (self. basecombobox)
Self. Connect (self. windowcombobox, signal ("currentindexchanged (INT)"), self. slotwindow)
Self. Connect (self. windowtextcombobox, signal ("currentindexchanged (INT)"), self. slotwindowtext)
Self. Connect (self. buttoncombobox, signal ("currentindexchanged (INT)"), self. slotbutton)
Self. Connect (self. buttontextcombobox, signal ("currentindexchanged (INT)"), self. slotbuttontext)
Self. Connect (self. basecombobox, signal ("currentindexchanged (INT)"), self. slotbase)
Gridlayout = qgridlayout ()
Gridlayout. addwidget (label1, 0, 0)
Gridlayout. addwidget (self. windowcombobox, 0, 1)
Gridlayout. addwidget (label2, 1, 0)
Gridlayout. addwidget (self. windowtextcombobox, 1, 1)
Gridlayout. addwidget (label3, 2, 0)
Gridlayout. addwidget (self. buttoncombobox, 2, 1)
Gridlayout. addwidget (label4, 3, 0)
Gridlayout. addwidget (self. buttontextcombobox, 3, 1)
Gridlayout. addwidget (label5, 4, 0)
Gridlayout. addwidget (self. basecombobox)
Self. ctrlframe. setlayout (gridlayout)
Def fillcolorlist (self, ComboBox ):
Colorlist = qcolor. colornames ()
For color in colorlist:
PIX = qpixmap (qsize (70, 20 ))
PIX. Fill (qcolor (color ))
ComboBox. additem (qicon (pix), color)
ComboBox. seticonsize (qsize (70, 20 ))
ComboBox. setsizeadjustpolicy (qcombobox. adjusttocontents)
Def createcontentframe (Self ):
Label1 = qlabel (self. tr ("select a value "))
Valuecombobox = qcombobox ()
Valuecombobox. additem ("1 ")
Valuecombobox. additem ("2 ")
Label2 = qlabel (self. tr ("enter a string "))
Stringlineedit = qlineedit ()
Textedittext = qtextedit (self. tr ("enter "))
Hlayout = qhboxlayout ()
Okbutton = qpushbutton (self. tr ("OK "))
Cancelbutton = qpushbutton (self. tr ("cancel "))
Hlayout. addstretch ()
Hlayout. addwidget (okbutton)
Hlayout. addwidget (cancelbutton)
Gridlayout = qgridlayout ()
Gridlayout. addwidget (label1, 0, 0)
Gridlayout. addwidget (valuecombobox, 0, 1)
Gridlayout. addwidget (label2, 1, 0)
Gridlayout. addwidget (stringlineedit, 1, 1)
Gridlayout. addwidget (textedittext, 2, 0, 1, 2)
Gridlayout. addlayout (hlayout, 3, 0, 1, 2)
Self. contentframe. setlayout (gridlayout)
Def slotwindow (Self ):
Colorlist = qcolor. colornames ()
Color = qcolor (colorlist [self. windowcombobox. currentindex ()])
P = self. contentframe. palette ()
P. setcolor (qpalette. Window, color)
Self. contentframe. setpalette (P)
Def slotwindowtext (Self ):
Colorlist = qcolor. colornames ()
Color = qcolor (colorlist [self. windowcombobox. currentindex ()])
P = self. contentframe. palette ()
P. setcolor (qpalette. windowtext, color)
Self. contentframe. setpalette (P)
Def slotbutton (Self ):
Colorlist = qcolor. colornames ()
Color = qcolor (colorlist [self. windowcombobox. currentindex ()])
P = self. contentframe. palette ()
P. setcolor (qpalette. Button, color)
Self. contentframe. setpalette (P)
Def slotbuttontext (Self ):
Colorlist = qcolor. colornames ()
Color = qcolor (colorlist [self. windowcombobox. currentindex ()])
P = self. contentframe. palette ()
P. setcolor (qpalette. buttontext, color)
Self. contentframe. setpalette (P)
Def slotbase (Self ):
Colorlist = qcolor. colornames ()
Color = qcolor (colorlist [self. windowcombobox. currentindex ()])
P = self. contentframe. palette ()
P. setcolor (qpalette. Base, color)
Self. contentframe. setpalette (P)
APP = qapplication (SYS. argv)
Main = palette ()
Main. Show ()
App.exe C _()
As follows:
Learning about pyqt UI color replacement (learning about pyqt highlights)