<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);">
<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">
<div dir="ltr">
<div dir="ltr">
<blockquote style="border-color: rgb(200, 200, 200); border-left: 3px solid rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102); margin-top: 0px; margin-bottom: 0px;">
<div dir="ltr">Il giorno sab 25 mag 2019 alle ore 20:18 Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com" target="_blank" rel="noopener noreferrer">kukovecmatic@hotmail.com</a>> ha scritto:<br>
</div>
<div>
<div dir="ltr">
<div style="color:black; font-size:12pt; font-family:Calibri,Helvetica,sans-serif">
<span>I made a QTabWidget with a custom tabBar in which I manually add a QGroupBox with QLabel</span><br>
</div>
<blockquote style="margin-top: 0px; margin-bottom: 0px;">
<div style="color:black; font-size:12pt; font-family:Calibri,Helvetica,sans-serif">
that acts as a close button with <i><b>self.setTabButton(index, QTabBar.RightSide, groupbox)</b></i>.</div>
</blockquote>
</div>
<div><br>
</div>
<div>First of all, why do you use a QGroupBox? As far as I understand, you are using it as a close button, but it doesn't seem to add any major advantage or implementation. If it's for look purposes, just go with stylesheets or custom painting. If it's to extend
 the TabBar capabilities, extend them in the TabBar; assigning functionality to a button that doesn't seem to belong to it doesn't make much sense.</div>
<div><br>
</div>
<div><br>
</div>
<blockquote style="margin-top: 0px; margin-bottom: 0px;">
<div dir="ltr">
<div style="color:black; font-size:12pt; font-family:Calibri,Helvetica,sans-serif">
I don't exactly know what caused this? I wish to get the standard behaviour back, can anyone help?</div>
</div>
</blockquote>
<div><br>
</div>
<div>I feel like you've being overshooting, as your code seems too complicated than it should.</div>
<div>For example: why do you need to constantly change the close "buttons" everytime the tab order is changed? As far as I can tell, the only thing that changes is their index, and you seem to want to hide/show them accordingly; why not just hide the button
 and/or change its index property?</div>
<div><br>
</div>
<div>I believe that the issue you're facing comes from the fact that you're constantly setting a new widget as the tabButton, which might interfere with widget size and positioning that occur while moving tabs (hence the odd graphical and mouse interaction
 behavior). As soon as I disable the _tab_moved_slot and _current_tab_changed connection slots, the QTabBar behaves as expected.<br>
<br>
You might want to think about a different and easier approach, and possibly rethink the whole concept you use while keeping it as simple as possible.</div>
<div><br>
</div>
<div><br>
</div>
<div>If I may, I also have some (unrequested) suggestions.</div>
<div><br>
First of all: why the unnecessary int() for every QSize declaration? You don't even need to use QSize for set[*]Size, as it also accepts numeric values. Moreover, you can even use floats, as they're automatically transformed to integers.</div>
<div><br>
</div>
<div>Then, If you need button-style behavior, just use a button :-)</div>
<div>You can use stylesheets to set icons, I also just discovered (thanks to you!) that you can set widgets graphical properties within the stylesheets like this:<br>
</div>
<div><br>
</div>
<div>
<div><font face="courier new,monospace">        button.setStyleSheet('''</font></div>
<div><font face="courier new,monospace">            QPushButton {</font></div>
<div><font face="courier new,monospace">                border: none;</font></div>
<div><font face="courier new,monospace">                qproperty-icon: url(up-icon.svg) off,</font></div>
<div><font face="courier new,monospace">                url(down-icon.svg) on;</font></div>
<div><font face="courier new,monospace">            }</font></div>
<div><font face="courier new,monospace">        ''')</font></div>
</div>
<div><br>
This allows you to set icons for both down and up states. Unfortunately, there are some bugs with this. First of all, a still unsolved bug prevents to set (some) properties for pseudo states, which means that you can't set an icon for the :hover state. Also,
 it seems that setting (some) other properties in the stylesheet (such as the border) prevents the successful update of the state icon. Nonetheless, since you only need a button with an icon and without text, you can use the simpler image syntax:</div>
<div><br>
</div>
<div>
<div><font face="courier new,monospace">        button.setStyleSheet('''</font></div>
<div><font face="courier new,monospace">            QPushButton {</font></div>
<div><font face="courier new,monospace">                border: 1px solid red;</font></div>
<div><font face="courier new,monospace">                image: url(up-icon.svg);</font></div>
<div><font face="courier new,monospace">            }</font></div>
<div><font face="courier new,monospace">            QPushButton:hover {</font></div>
<div><font face="courier new,monospace">                border: 1px solid green;</font></div>
<div><font face="courier new,monospace">                image: url(down-icon.svg);</font></div>
<div><font face="courier new,monospace">            }</font></div>
<div><font face="courier new,monospace">        ''')</font></div>
</div>
<div><br>
</div>
<div>This works as long as there's no button text: whenever you set it, you'll see that the text is overimposed on the icon, and there's no known method of setting the background alignment according to the button's text (or vice versa), since no margin or padding
 setting will correctly affect the result.</div>
<div>If you need to do more complex interaction, set an alternate stylesheet for enterEvent and set it back on leaveEvent, but at this point you could obviously use setIcon() as well.<br>
</div>
<div><br>
</div>
<div>Somehow trivial, but it's a good practice: as PEP8 suggests, it's always better to use "if cond is [not]" comparison whenever a singleton comes in place; as far as I know of, None is the most important one to keep in mind, as it's an actual singleton in
 both Python 2 and 3 (you can't create an instance of None), while technically you could create a new "True" variable in Python 2. While "cond == None" works, it's not a preferred pattern, not from a programming perspective, but mostly from a readability one
 (which also means better and easier debugging). That said, the problem also comes whenever you're using comparisons in a "light" fashion: obviously, a simple "if not cond" doesn't work as expected if you're expecting None and you get False, 0, or an empty
 string.<br>
</div>
<div><br>
</div>
<div>Also, remember that if you use external resources (like the button pixmaps in your case) you should attach them. While it wasn't much of an issue in your case, it might be a problem in other situations: QPixmaps that are init-ed with a non existing file
 are null pixmaps, so their size is invalid, which might become a problem if, for example, the issue at hand is about painting or sizing.</div>
<div><br>
</div>
<div>Finally, when attaching an example, it's always better to make it as minimal as possible. When people see hundreds of lines of code and find that it's overly complicated, they might be discouraged in trying to help you, since they'd lose much of their
 time trying to understand what you're really trying to achieve while being lost in dozens of unnecessary declarations, functions and methods. I know it can be annoying, but it really does help: first of all, in my experience I've learnt that recreating the
 example usually results in being able to find the solution on your own (see <a href="https://en.wikipedia.org/wiki/Rubber_duck_debugging" target="_blank" rel="noopener noreferrer">https://en.wikipedia.org/wiki/Rubber_duck_debugging</a> ), but, anyway, it's
 always better to lose 15-20 minutes of your time "minimizing" your example (with the possibility of even finding the solution on your own) than losing the opportunity of having somebody who could actually help you but didn't want (or wasn't able) to find the
 time to "filter out" your code.</div>
<div><br>
</div>
<div>Good luck,</div>
<div>Maurizio</div>
<div><br>
</div>
<div><br>
</div>
</div>
-- <br>
<div dir="ltr">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br>
</div>
<div dir="ltr"><a href="http://www.jidesk.net" target="_blank" rel="noopener noreferrer">http://www.jidesk.net</a></div>
</blockquote>
<div dir="ltr"><br>
</div>
<div dir="ltr">Hey Mauricio,</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Thanks for pinpointing that commenting out <i>_tab_moved_slot </i>
and <i>_current_tab_changed</i> signals.</div>
<div dir="ltr">Now I know where to look at, excellent.<br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Excellent find on the button stylesheets, I did not know you could do that!<br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">You asked why I'm using a groupbox? It's because there needs to be the ability to add as many buttons as needed to any tab.</div>
<div dir="ltr">Why the constant hiding/showing of different buttons when the index changes? That is because only the
<i>close-button</i> is shown on non-active tab,</div>
<div dir="ltr">while <i>all-other-buttons + close-button</i> are shown only on the active tab. Plus there has to be an ability to hide any button on a particular tab as needed, even if it is the active tab.</div>
<div dir="ltr">So in short, I have two groupboxes:</div>
<div dir="ltr">
<ul>
<li>one that holds the close-button (in my complete code it can also be none if the tab is not closable)</li><li>one that holds all additionally added buttons plus a close button, if the tab is closable</li></ul>
which I use to switch according to the activity of the tab when the current index changes. That is why there is so much code
<br>
</div>
<div dir="ltr">for updating the tab index, and also for resizing when the whole application scale factor changes.<br>
</div>
<div dir="ltr">If you have any suggestions of how to make this simpler, I would be glad to hear it.<br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Thanks for the PEP8/None suggestion. I have been trying to hold to it, but sometimes I just forget, sorry.<br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">As far as the example, I apologize, I forgot to attach the images. I also tried to minimize the code without breaking anything,</div>
<div dir="ltr">that is why there was stuff like <i>int(20)</i> in it, as before it was a more complex expression.</div>
<div dir="ltr">I am attaching the more complete example with the images. In the example code pressing the test button adds a new tab with</div>
<div dir="ltr">an additional tab-button on it, that is only visible when the tab is active, so you can see the actual behavior at runtime.<br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Thanks,</div>
<div dir="ltr">Matic<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>