<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi guys,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I have a subclassed QTabBar which I want to manually change the color of each tab.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
After a lot of trial-and-error, I tried this to make all the tabs red:</div>
<blockquote style="margin-top:0;margin-bottom:0">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><span style="font-size: 10pt;">def paintEvent(self, event):</span></i>
<div><i><span style="font-size: 10pt;"> painter = data.QStylePainter(self)</span></i></div>
<div><i><span style="font-size: 10pt;"> opt = data.QStyleOptionTab()</span></i></div>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><span style="font-size: 10pt;"> painter.save()</span></i></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><span style="font-size: 10pt;"> </span><br>
</i></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><span style="font-size: 10pt;"> for i in range(self.count()):</span></i>
<div><i><span style="font-size: 10pt;"> self.initStyleOption(opt, i)</span></i></div>
<div><i><span style="font-size: 10pt;"> items = (</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Window,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Background,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.WindowText,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Foreground,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Base,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.AlternateBase,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.ToolTipBase,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.ToolTipText,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.PlaceholderText,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Text,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Button,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.ButtonText,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.BrightText,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Light,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Midlight,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Dark,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Mid,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Shadow,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Highlight,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.HighlightedText,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Link,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.LinkVisited,</span></i></div>
<div><i><span style="font-size: 10pt;"> )</span></i></div>
<div><i><span style="font-size: 10pt;"> groups = (</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Disabled,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Active,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Inactive,</span></i></div>
<div><i><span style="font-size: 10pt;"> data.QPalette.Normal,</span></i></div>
<div><i><span style="font-size: 10pt;"> )</span></i></div>
<div><i><span style="font-size: 10pt;"> color = data.QColor(0xffff0000)</span></i></div>
<div><i><span style="font-size: 10pt;"> for g in groups:</span></i></div>
<div><i><span style="font-size: 10pt;"> for p in items:</span></i></div>
<div><i><span style="font-size: 10pt;"> opt.palette.setColor(g, p, color)</span></i></div>
<div><i><span style="font-size: 10pt;"> opt.palette.setBrush(g, p, color)</span></i></div>
<div><i><span style="font-size: 10pt;"> painter.setBrush(data.QBrush(data.QColor(color)))</span></i></div>
<div><i><span style="font-size: 10pt;"> painter.setPen(data.QPen(data.QColor(color)))</span></i></div>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><span style="font-size: 10pt;"> painter.drawControl(data.QStyle.CE_TabBarTabLabel, opt)</span></i></div>
</blockquote>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><br>
</i></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><span style="font-size: 10pt;"> painter.restore()</span></i><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Now this works, but only for the non-currently selected tabs, the selected tab ALWAYS has black text and I have no idea why.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Here is a screenshot: <img size="4559" contenttype="image/png" style="max-width: 100%; user-select: none;" unselectable="on" tabindex="-1" data-outlook-trace="F:1|T:1" src="cid:09c89968-b2bd-4534-9a54-d812603119da"><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The "string.h" tab is the currently selected one.<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Any ideas what I'm doing wrong or missing?</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Matic<br>
</div>
</body>
</html>