[PyKDE] Color in label of QTabWidget tab

Jim Bublitz jbublitz at nwinternet.com
Sat Nov 16 04:03:00 GMT 2002


On 16-Nov-02 Sundance wrote:
> I'm trying to write an app (Qt 3.0, PyQt 3.4) that will monitor
> several connections at the same time. Each connection will have
> its own widget  within a QTabWidget. I would like to reflect
> changes to a given connection's state in it's tab's label.
> Current solutions I've envisionned are:
> - Modifying the label's text. By prepending a '*' when something
> is received on the connection, for example.
> - Adding an icon to the tab and change the icon according to the 
> connection's state.
> Those two are easy to do.
> But what I'd really like is:
> - Change the color of the tab's label depending on the
> connection's state.

I'm not clear on whether you want to change the color of a QLabel
owned buy a QTabWidget, or you want to change the label (actually
QTab/QTabBar) of a QTabWidget (the part that makes it look like a
file folder). For the QLabel: it's a QWidget descendant, so it has
all of the QWidget methods for setting colors (see Qt QWidget docs
- foreground, background, etc). You can also overload the paint
method in a subclass.

To change the color of a single tab in a QTabBar, it looks like
you'd have to subclass QTabBar and overload the paint() method so
it knows what color each tab should be (paint() gets the index
number of the tab it's painting). Also look at the QTabWidget docs
for info about setting a new QTabBar.

Jim




More information about the PyQt mailing list