Monday, February 23, 2009

QTreeWidgetItem coloring problem on Windows Vista

Problem:

http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=225056

Solved with Qt 4.5

I found out this problem while attempting to use the background coloring for a QTreeWidgetItem using the void QTreeWidgetItem::setBackground(int column, const QBrush & brush) method while programming on Vista. The problem is that the tree items only gets colored on mouse hover, else the color does not hold.

I have posted this problem long ago on the QtForums.org and then found out this to be an issue Qt has with Vista (http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=225056
). This issue has not been fixed yet.

Solution:
The workaround however seemed to be amazingly simple, though I came across it quite by an accident. All that is needed to get this method take its usual course on Vista is to set the Application Style to that of Windows XP. This can easily be achieved by calling QApplication::setStyle("WindowsXP") at the program initialization... maybe in the constructor.