0

The idea that I am looking to apply in my code is the create an "Add Tab" button in my tab bar. The likes of which can be seen in any browser like chrome. This requires that I must update the position of the button depending on what is the last tab in the tab bar.

The add tab button that I am trying to replicate

To do so I am manually updating the position of the button using the setGeometry method of the QRect of the toolbutton. (example code snippet below)

  self.tabButton.setGeometry( x+100, 0, self.tabButton.sizeHint().width(), self.tabButton.sizeHint().height())

which kind of works in terms of the horizontal placement of the button. However vertically it seems to be a little off

Vertical offset of the add tab button

I have tried to adjust the vertical positioning of this Qtoolbutton manually as well like in the following snippet

  self.tabButton.setGeometry( x+100, 10, self.tabButton.sizeHint().width(), self.tabButton.sizeHint().height())

This does position the add tab button better however a wierd this that happens when I do this is that the button becomes unresponsive. It took me quite a few tries to find out that this is somehow reducing the clickable area of the button. Which means that the button only works if if the user precisely clicks a very specific and small area towards the top of the button (this area is not the same as the previously shown position of the button). The only responsive part of the button in this version is the area marked red in the picture below.

vertically adjusted button with a shrinked clickable area

Can someone please help me identify the possible issues in this case and/or if I am missing anything when setting the button geometries.

  • please read [example] – Alexander Jun 21 '22 at 10:02
  • Please provide a [mre]. – musicamante Jun 21 '22 at 10:02
  • Here you should find a possible solution: https://stackoverflow.com/questions/65467945/closetab-function-it-closes-more-than-one-tab-in-pyqt5 – Jonas Vieira de Souza Jun 21 '22 at 17:32
  • You should find a possible solution here: [65467945](https://stackoverflow.com/questions/65467945/closetab-function-it-closes-more-than-one-tab-in-pyqt5) – Jonas Vieira de Souza Jun 21 '22 at 17:39
  • I have been trying to create a minimal reproducable example, however everything seemed to work fine in that and I couldnt reproduce the bug. I must have been missing something. On the hand thanks to @JonasVieiradeSouza I was able to pick things that I needed from the example questionaire and create a work around to my solution which kind of is the better approach since this does not require additional handling of cases where the number tabs is large enough to create a scrollable area in the tab bar. – Sarim Charania Jun 30 '22 at 14:46

0 Answers0