2013-07-04 47 views

回答

7

使用QWidget::palette访问控件的调色板和QPalette::color获得背景色:

color = widget.palette().color(QPalette.Background) 
print color.red(), color.green(), color.blue() 
+1

错字:'QPalette :: Background'其实 – thiagowfx

+3

不,它是Python中的'.'。 –

+1

Oooops,对不起,你是对的,我想到了C++。 – thiagowfx

0
import sys 
from PyQt4 import QtGui, QtCore 

class MainWin(QtGui.QDialog): 
    def __init__(self,parent=None): 
     QtGui.QDialog.__init__(self,parent) 
     pal=QtGui.QPalette() 
     role = QtGui.QPalette.Background 
     pal.setColor(role, QtGui.QColor(0, 0, 255)) 
     self.setPalette(pal) 

或样式表

 self.setStyleSheet("background:blue) 
+0

OP是询问如何获取颜色,而不是如何设置。 –