<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);">
Hello Mauricio,</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 played around with all the QStyle stuff, but could not get it to work properly.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Once you set a stylesheet (at least on Windows) the active tab is always painted with the color set in the stylesheet.</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);">
But there is a workaround: do NOT set any color settings in the stylesheet concerning the text color (the
<i><b>color</b></i> attribute) and</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
then use <i><b>QTabBar.setItemTextColor </b></i>on each tab and painting the current tab's background manually, every time something changes in the tab bar layout (tabInserted, tabRemoved, ...).</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
It is a bit more code, but it works:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<img size="45955" contenttype="image/gif" style="max-width: 100%; user-select: none;" unselectable="on" tabindex="-1" data-outlook-trace="F:1|T:1" src="cid:12627e81-1074-49e9-a24e-a1caa2797c5e"><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 another issue has come up. When click&dragging an active tab, the drag image is that of the stylesheet painted tab,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
not the image of the "blue" one that is actually painted in the tab bar:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<img size="35855" contenttype="image/gif" style="max-width: 100%; user-select: none;" unselectable="on" tabindex="-1" data-outlook-trace="F:1|T:1" src="cid:d6f16b02-7da7-444c-bc78-c6feffecd9a2"></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The image is a white background and white text, that's why it looks like the text disappears.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I have no idea where this image is set. Is there a way to fix this?<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);">
Thanks,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Matic<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Maurizio Berti <maurizio.berti@gmail.com><br>
<b>Sent:</b> Saturday, June 5, 2021 3:47 AM<br>
<b>To:</b> Matic Kukovec <kukovecmatic@hotmail.com><br>
<b>Cc:</b> RedHuli <redhuli.comments@gmail.com>; pyqt@riverbankcomputing.com <pyqt@riverbankcomputing.com><br>
<b>Subject:</b> Re: QTabBar tab text painting?</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Il giorno ven 4 giu 2021 alle ore 18:48 Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com">kukovecmatic@hotmail.com</a>> ha scritto:<br>
</div>
<div class="x_gmail_quote">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="font-size:12pt">The idea is that there are multiple QTabWidget (with their respective tabbar's) in the window and the one that has focus is active, </span><span style="font-size:12pt">the others are not.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
When an inactive QTabWidget becomes active, and with it, it's tabbar, it needs a style update:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
either an update with "<i><b>setStyleSheet</b></i>" or adding a property (for this example let's call the property "<i><b>active</b></i>") to the style sheet</div>
</div>
</blockquote>
<div><br>
</div>
<div>The result shown in the animation is probably a "non-bug": polishing/unpolishing and updating the stylesheet (which does the same thing) can result in unexpected behavior, especially for complex widgets like QTabBar *and* when the platform style is in
 effect.</div>
<div>Consider that the tabs' translation and painting is completely private and managed by the style: there's no API to directly control the offset, and you can only "deduce" it using QTabBar.tabRect. If deeper and advanced control is required, you need to
 create your own tab widget (using QStackedWidget, which is exactly what QTabWidget does) and create a custom tab bar. Not easy, not painless, but feasible.</div>
<div><br>
</div>
<div>From what I can see, though, those tabs look pretty simple, so a possible solution could be to *completely* style the QTabBar and properly set all the required pseudo states, which *should* theoretically work around the issue.</div>
<div><br>
</div>
<div>The problem of the non colored active tab could come from a combination of factors, but it's a bit tricky to find the actual source. *Theoretically*,
<font face="monospace">drawControl(CE_TabBarTabLabel)</font> *should* use the default QCommonStyle drawItemText using the WindowText role (so, it should work since you set that too), but QStyle implementation is complex and there could be some bug somewhere.</div>
<div>A possible fix for that could be to *force* the fusion style (which is usually more stylesheet-compliant) for the tab bar only:<br>
</div>
<div><br>
</div>
<div><font face="monospace">    self.setStyle(QtWidgets.QStyleFactory.create('fusion'))</font><br>
</div>
<div><br>
</div>
<div>You would need to properly create the icons for the close button, but since it seems that you're already setting a custom widget for that, it shouldn't be a problem.</div>
<div><br>
</div>
<div>Alternatively, you could set a QProxyStyle for the custom tab bars, and override the drawItemText: in this way you'll know if it gets actually called and eventually find a way to change the color (be aware that drawItemText doesn't receive any usable property,
 so you'll need to manually set an attribute before calling drawControl).</div>
<div><br>
</div>
<div>Anyway, if you could provide a minimal reproducible example of your situation, we might probably find alternative solutions or, at least, verify that there's actually a bug in the windowsvista style.</div>
<div><br>
</div>
<div>Finally, but unrelated.</div>
<div>If you want to set the same color for all groups, you can do it more easily (and it'll be faster too):</div>
<div>
<ul>
<li>setColor is actually an override of setBrush (see <a href="https://code.woboq.org/qt5/qtbase/src/gui/kernel/qpalette.h.html">https://code.woboq.org/qt5/qtbase/src/gui/kernel/qpalette.h.html</a> );<br>
</li><li>the setColor/setBrush overrides that don't use the group, actually set the color for *all* groups;<br>
</li><li>QPalette has two useful variables named "All" and "NColorRoles"; using "All" results in calling setBrush for all color groups (similarly to setBrush/setColor without the group), while you can cycle through all roles to set the individual colors;<br>
</li></ul>
</div>
<div>With the following code you can get the exact same result, but with much better performance: you don't need to create tuples everytime, and most of the job is done on the C++ side).<br>
</div>
<div><br>
</div>
<div>
<div><span style="font-family:monospace">    palette = self.palette()</span><br>
</div>
<div><font face="monospace">    brush = QtGui.QBrush(QtGui.QColor('red'))</font></div>
<div><font face="monospace">    for role in range(palette.NColorRoles):</font></div>
<div><font face="monospace">        palette.setBrush(palette.All, role, brush)</font></div>
</div>
<div><br>
</div>
<div>Consider that, due to the changes in PyQt6, the "role" variable should probably be converted using the enum:</div>
<div><br>
</div>
<div>
<div><span style="font-family:monospace">    palette.setBrush(palette.All, palette.ColorRole(role), brush)</span><br>
</div>
</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Maurizio.</div>
<div><br>
</div>
</div>
-- <br>
<div dir="ltr" class="x_gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br>
<a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">Il giorno ven 4 giu 2021 alle ore 18:48 Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com">kukovecmatic@hotmail.com</a>> ha scritto:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hello Joshua,</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 for the information.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
The idea is that there are multiple QTabWidget (with their respective tabbar's) in the window and the one that has focus is active,
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
the others are not.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
When an inactive QTabWidget becomes active, and with it, it's tabbar, it needs a style update:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
either an update with "<i><b>setStyleSheet</b></i>" or adding a property (for this example let's call the property "<i><b>active</b></i>") to the style sheet,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
setting the "<i><b>active</b></i>" property to <i><b>True</b></i> and then using "<i><b>QTabBar.unpolish(); QTabBar.polish()"</b></i> to refresh it. If you</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
don't do the <i><b>polish/unpolish</b></i>, the changing of the property does nothing. For example, the selected tab has this style in the stylesheet:</div>
<blockquote style="margin-top:0px; margin-bottom:0px">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="font-size:10pt">QTabBar[indicated=false]::tab::selected {</span>
<div><span style="font-size:10pt">    background-color: #ffffffff;</span></div>
<div><span style="font-size:10pt">    color: #ff000000;</span></div>
<div><span style="font-size:10pt">    font: normal;</span></div>
<div><span style="font-size:10pt">}</span></div>
<div><span style="font-size:10pt">QTabBar[indicated=true]::tab::selected {</span></div>
<div><span style="font-size:10pt">    background-color: #ff0000ff;</span></div>
<div><span style="font-size:10pt">    color: #ffffffff;</span></div>
<div><span style="font-size:10pt">    font: bold;</span></div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="font-size:10pt">}</span></div>
</blockquote>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Now, when doing this (either with <i><b>setStyleSheet </b></i>or updating the property) the tabs
<i><b>snaps </b></i>to the right, like this:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<img size="68878" style="max-width:100%" data-outlook-trace="F:1|T:1" src="cid:179d95c72184180ea9c2"></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 would love it if this could be done with stylesheets and without the snap, but I don't know how.</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 further information would be greatly appreciated!</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>
<div id="x_gmail-m_-544102958539469207appendonsend"></div>
<hr style="display:inline-block; width:98%">
<div id="x_gmail-m_-544102958539469207divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> RedHuli <<a href="mailto:redhuli.comments@gmail.com" target="_blank">redhuli.comments@gmail.com</a>><br>
<b>Sent:</b> Friday, June 4, 2021 5:13 PM<br>
<b>To:</b> Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com" target="_blank">kukovecmatic@hotmail.com</a>>;
<a href="mailto:pyqt@riverbankcomputing.com" target="_blank">pyqt@riverbankcomputing.com</a> <<a href="mailto:pyqt@riverbankcomputing.com" target="_blank">pyqt@riverbankcomputing.com</a>><br>
<b>Subject:</b> Re: QTabBar tab text painting?</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hello Matic, 
<div><br>
</div>
<div>I was looking at your issue and was trying to think how to help. But I was confused by what you said:</div>
<div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
and the tabbar's view snaps to the right. This has been very annoying for users as when they switch<br>
to an inactive QTabWidget that becomes active, the whole tabbar view changes.</blockquote>
</div>
<div>Do you mean that the tabs actually snap to the right, like move? Would you care to explain just a bit more?</div>
<div><br>
</div>
<div>As for inactive and active tabs, </div>
<div><br>
</div>
<div>
<div><font face="monospace">style_sheet = """QTabBar::tab {background: grey; }</font></div>
<div><span style="font-family:monospace; color:rgb(0,0,0)">                 QTabBar::tab:selected { color: red; }</span></div>
<div style="color:rgb(0,0,0)"><font face="monospace">                 QTabBar::tab:!selected {color: blue; }"""</font></div>
<div><font face="monospace">self.tabWidget.setStyleSheet(style_sheet</font><span style="font-family:monospace">)</span></div>
</div>
<div><br>
</div>
<div>Not sure if that helps your case, I know you said stylesheets aren't helping. But it is possible to change the color and appearance of a tab depending upon whether or not it is selected with style sheets. Was trying to understand more how your QTabWidget
 is set up to better help. Perhaps manipulating the style sheets more may help give the tabs an appearance of enabled or disabled. Not sure if you have looked into that option. </div>
<div><br>
</div>
<div>You can also play around with the QTabWidget::pane and QTabWidget::tab-bar using style sheets, perhaps changing their alignment and position depending upon your circumstances. </div>
<div><br>
</div>
<div>I have always found it easier to manipulate the appearance of widgets with style sheets, rather than using QPalette. </div>
<div><br>
</div>
<div>Joshua Willman</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div>
<div dir="ltr">On Fri, Jun 4, 2021 at 10:04 PM Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com" target="_blank">kukovecmatic@hotmail.com</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hello Maurizio,</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)">
You are right about the superfluous stuff, I copy pasted from an actual working example.<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
The painter save/restore is still in there because I forgot to remove it in this example.<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
And yes, <b><i>data </i></b>is the PyQt5 package with all sub-packages, all of them in one namespace.</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)">
The reason stylesheets are not usable in my case, is that I need to switch between an</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
active and inactive mode, and when setting a new stylesheet, the scroll offset is not remembered</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
and the tabbar's view snaps to the right. This has been very annoying for users as when they switch</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
to an inactive QTabWidget that becomes active, the whole tabbar view changes. When you have</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
a lot of tabs, then the user sometimes doesn't know where the active tab "jumped" to.<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
That is why I'm using the overridden <i><b>paintEvent</b></i>.</div>
<blockquote style="border-color:rgb(200,200,200); border-left-width:3px; border-left-style:solid; padding-left:1ex; margin-left:0.8ex; color:rgb(102,102,102)">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Anyway, the main issue here is that you're probably using Windows, and the Windows QStyle does paint some things a bit differently, including possibly ignoring the palette of the style option (but, hey, that could also be a bug, unfortunately I cannot test
 it).</div>
</blockquote>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Yes, I'm on Windows.</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 for the help, I will investigate further.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
If anyone can shed more light on where the problem could be, please let me know.<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)">
Regards,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Matic<br>
</div>
<div id="x_gmail-m_-544102958539469207x_gmail-m_-6564885657798896321appendonsend">
</div>
<hr style="display:inline-block; width:98%">
<div id="x_gmail-m_-544102958539469207x_gmail-m_-6564885657798896321divRplyFwdMsg" dir="ltr">
<font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Maurizio Berti <<a href="mailto:maurizio.berti@gmail.com" target="_blank">maurizio.berti@gmail.com</a>><br>
<b>Sent:</b> Friday, June 4, 2021 3:46 PM<br>
<b>To:</b> Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com" target="_blank">kukovecmatic@hotmail.com</a>><br>
<b>Cc:</b> <a href="mailto:pyqt@riverbankcomputing.com" target="_blank">pyqt@riverbankcomputing.com</a> <<a href="mailto:pyqt@riverbankcomputing.com" target="_blank">pyqt@riverbankcomputing.com</a>><br>
<b>Subject:</b> Re: QTabBar tab text painting?</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div>Hello Matic,</div>
<div><br>
</div>
The whole resetting the palette in the for loop is completely unnecessary (especially if done every time in a for loop, you can create a palette the first time, and then overwrite opt.palette, but that would be unnecessary anyway since the palette should not
 change between tabs).
<div>Also, the painter save/restore is completely pointless like that: the point of saving the state of the painter is that you can temporarily change painter settings and restore the previous state (which should also match the state level: it's not really
 clear since the formatting is not monospaced, but it seems that you're calling painter.restore() in the for loop, and if that's the case, you should not, as you'd have unmatched levels of saved states). Since you're not painting anything before or after that,
 there's no benefit.</div>
<div><br>
</div>
<div>Anyway, the main issue here is that you're probably using Windows, and the Windows QStyle does paint some things a bit differently, including possibly ignoring the palette of the style option (but, hey, that could also be a bug, unfortunately I cannot
 test it).</div>
<div><br>
</div>
<div>That said, if you only want to change the color of the tab text, subclassing and overriding the paintEvent is a bit too much (and also risky: your implementation doesn't take into account movable tabs, which is really tricky). I'd suggest a more simpler:</div>
<div><br>
</div>
<div><font face="monospace">self.tabWidget.setStyleSheet('QTabBar { color: red; }')</font></div>
<div><br>
</div>
<div>Which should solve the whole problem on any platform.</div>
<div><br>
</div>
<div>Be aware that it's very important that you use the class selector (unless you set the stylesheet on the tab bar), if you use generic/universal properties you'll get unexpected results, especially for a container widget such a QTabWidget.</div>
<div>So, *never* do the following: it works, but it works very badly.</div>
<div><br>
</div>
<div><font face="monospace">self.tabWidget.setStyleSheet('color: red') # NO!</font></div>
<div><br>
</div>
<div><br>
</div>
<div>Maurizio</div>
<div><br>
</div>
<div>PS: it took me a while to understand what "data" actually was; I'd strongly suggest you against that choice, "data" is a very generic word and doesn't reflect what it refers to in your code (and it's also very confusing to others reading your code): what
 happens whenever you have a function that *actually* uses some "data"? Why should you then choose another word instead of an obvious name, because you already used that name for a wrong reference and you cannot overwrite it because it's required in the function
 scope?</div>
</div>
</div>
<br>
<div>
<div dir="ltr">Il giorno ven 4 giu 2021 alle ore 10:26 Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com" target="_blank">kukovecmatic@hotmail.com</a>> ha scritto:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div 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:0px; margin-bottom:0px">
<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" style="max-width:100%" data-outlook-trace="F:1|T:1" src="cid:179d95c7218cb971f161"><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>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br>
<a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br>
<a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div>
</body>
</html>