Widget under QTabBar with unwanted frame

I have a problem with QTabBar / QTabWidget. This is what my program currently looks like using QTabBar:

enter image description here

As you can see, there is an ugly line between QTabBar and QScrollArea. This line is part of the QScrollArea framework, which I cannot just get rid of, because it is required on three sides. I understand that I can use QTabWidget, but then I will need to create a widget for each tab, which is not possible here: the contents of QScrollArea change according to the selected tab, but there is only one QScrollArea widget. (Duplicating it every time a new tab is created will cause its own problems.)

So does anyone know a way: (i) tell QScrollArea to draw a frame without the top line; or
(ii) use the same widget for each tab in a QTabWidget?

Update 3 . For a different approach, see my answer below.

Update 1 I implemented the zvezdi suggestion and the ugly line disappeared:

enter image description here

This is an improvement. But this is not so. Look at the gaps between the scrollbars and the border. On the right, two pixels instead of one; at the bottom are three pixels. And the space on the right between the QScrollArea border and the mainWidget border is one pixel too large. This is due to the QTabWidget border style that I am losing due to my sanity trying to change. If I say:

MyTabWidget -> setStyleSheet ("QTabWidget::pane { margin: 0px,0px,0px,0px }") ; 

then the fields seem correct, but the borders disappear:

enter image description here

If I say:

 MyTabWidget -> setStyleSheet ("QTabWidget::pane { " " margin: 0px,0px,0px,0px;" " border: 1px solid darkgray;" "}") ; 

then I almost returned to where I started:

enter image description here

If I try to fix this, follow these steps:

 ApplicationTabWidget -> setStyleSheet ("QTabWidget::pane { " " margin: 0px,0px,0px,0px;" " border: 1px solid darkgray;" " border-top: 0px;" "}") ; 

then again I mock my pain:

enter image description here

Update 2 If I forget setStyleSheet and just turn it on documentMode , this is what I get:

enter image description here

Please someone, tell me that I am stupid and there is a completely simple solution for all this.

+7
source share
3 answers

You said β€œthe contents of the QScrollArea change according to the selected tab”, if I assume that this is incorrect, and what you mean is that the contents of the widget inside the scroll pane change, then you can try the following:

Make as many QScrollArea objects as many tabs as you need in your QTabWidget, but only one, for example QTextEdit, which you will show in each scroll pane and what content will change when you change the tab (takeWidget () from the old QScrollArea tab and setWidget () in a new tab QScrollArea)

I don’t know how you developed your code, but to try my suggestion, your code should be designed around the widget inside QScrollArea, and not QScrollArea itself.

+2
source

If I don't understand, if you turn off the QScrollArea border by setting frameShape to NoFrame , the tab widget still has its frame lines on the sides and bottom where you want.

+2
source

I tried a different approach: use QTabBar , as in the first screenshot, and then change the style for MyScrollArea (obviously, retrospectively):

 MyScrollArea -> setStyleSheet ("QScrollArea {" "border: 1px solid #898C95;" "border-top: 0px;" " }") ; 

This is the result:

enter image description here

Almost correct! There are three problems:
- a small square at the intersection of two scroll bars skips its lower border (but it is drawn if I click on the scroll bars or resize the window, or the main window loses focus); - colur #898C95 hardcoded, so it will be wrong if the user changes the style. But if I leave the border style, then the whole border will be painted white. Is there a way to query the current border color of a style?
- most seriously, the background color of the breakpoint widget on the left side is no longer white.

But I think I spent enough time on this! I will stick to this decision if no one can offer something else to try.

0
source

All Articles