<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"><div dir="ltr">Il giorno sab 25 mag 2019 alle ore 20:18 Matic Kukovec <<a href="mailto:kukovecmatic@hotmail.com">kukovecmatic@hotmail.com</a>> ha scritto:<br></div><div class="gmail_quote"><blockquote class="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">I made a QTabWidget with a custom tabBar in which I manually add a QGroupBox with QLabel</span><br></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
that acts as a close button with <i><b>self.setTabButton(index, QTabBar.RightSide, groupbox)</b></i>.</div></div></blockquote><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 class="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)">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">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" class="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></div></div></div>