[PyKDE] QTreeWidget and QPalette

hanzz hanzz.k at gmail.com
Mon Mar 5 19:42:44 GMT 2007


Hi,
i have problem with setting QTreeWidget QPalette. If i set alpha channel for 
QTreeWidget, then alpha channel is setted for all mainwindow too. What is 
bad?

This is the test source code. I'm using PyQt-x11-gpl-4.1.1 and qt4.2.1-2

try:
	from PyQt4 import QtCore, QtGui
except:
	print "PyQt4 is not installed."
import sys

class mainWindow(QtGui.QMainWindow):
	def __init__(self,parent=None):
		apply(QtGui.QMainWindow.__init__,(self,parent))
		# central widget
		self.setCentralWidget(QtGui.QWidget(self))
		# layout
		layout=QtGui.QVBoxLayout(self.centralWidget())
		# we will see palette color change on this widget
		self.lineEdit=QtGui.QLineEdit(self)
		layout.addWidget(self.lineEdit)
		# we will change palette of this tree widget
		self.treeWidget=treeWidget(self)
		layout.addWidget(self.treeWidget)

class treeWidget(QtGui.QTreeWidget):
	def __init__(self,parent=None):
		apply(QtGui.QTreeWidget.__init__,(self,parent))
		# if we set alpha channel then alpha channel will not set only for tree 
widget
		# but for mainWindow.lineEdit too.
		palette=QtGui.QPalette()
		color=palette.color(QtGui.QPalette.Base)
		color.setAlpha(50) # for example 50
		palette.setColor(QtGui.QPalette.Base,color)
		self.setPalette(palette)
		
		# i tried this too
		#palette=self.viewport().palette()
		#color=palette.color(QtGui.QPalette.Base)
		#color.setAlpha(50) # for example 50
		#palette.setColor(QtGui.QPalette.Base,color)
		#self.viewport().setPalette(palette)

app = QtGui.QApplication(sys.argv)
win = mainWindow()
win.show()
sys.exit(app.exec_())




More information about the PyQt mailing list