10

How to get background color of a dialog/window in RGB format?

Jomme
  • 1,256
  • 4
  • 14
  • 26

3 Answers3

13

Use QWidget::palette to access widget's palette and QPalette::color to obtain the background color:

color = widget.palette().color(QPalette.Background)
print color.red(), color.green(), color.blue()
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
2

http://qt-project.org/doc/qt-4.8/qwidget.html#palette-prop

http://qt-project.org/doc/qt-4.8/qpalette.html

http://qt-project.org/doc/qt-4.8/qpalette.html#ColorRole-enum

QPalette::Window - 10 - A general background color.

QPixmap::grabWindow(); can get you any part of the desktop.

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80
-1
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)

or with stylesheet

      self.setStyleSheet("background:blue)
raton
  • 418
  • 5
  • 14