3

I am facing a problem with QScrollArea.

In particular I can not find the right QSS rule for removing the 3px space between QSrollArea QFrame and QScroll.

The space I'd like to remove is the one pointed by the red arrow in the picture. I also added a blue border to the internal QFrame of the QSrollArea, but it seems to end correctly.

The image can be found here: http://i58.tinypic.com/2h71a2c.png

I am using QT 4.8.5 on a SLED 11 SP2 (under GNOME).

My QSS looks like this:

QScrollArea {
    background: transparent;
}

QScrollArea > QWidget > QWidget
{
    background: transparent;
    border: 1px solid black;
    margin: 0px 0px 0px 0px;
}    

QScrollBar:horizontal
{
    border: 1px solid #999999;
    background:white;
    height:7px;
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;
}

QScrollBar::handle:horizontal {
    background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));
    min-width: 20px;
}

QScrollBar::add-line:horizontal {
    background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));
    height: 0px;
    subcontrol-position: right;
    subcontrol-origin: margin;
}

QScrollBar::sub-line:horizontal {
    background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));
    height: 0px;
    subcontrol-position: left;
    subcontrol-origin: margin;
}

Any Ideas?

Thanks.

Lorenzo
  • 81
  • 1
  • 5
  • This is apparently a defect in Qt itself. See http://stackoverflow.com/a/11268557/266309 for a solution (you need to subclass QScrollArea and override the `setViewportMargins` method). – waldyrious Oct 14 '16 at 12:02

1 Answers1

0

Is it imperatively necessary to do it from QSS and QSS only? I think changing the layoutBottomMargin of the scrollAreaWidgetContents(i.e. the widget inside the QScrollArea) will solve the problem.

Iuliu
  • 4,001
  • 19
  • 31
  • It is not imperative. But as my picture shows i put a blue border on the widget inside se scroll area and i set the margin to 0. – Lorenzo Oct 28 '14 at 08:07
  • It seems that there is some kind of QT layout that put the scroll bar under the content widget... – Lorenzo Oct 28 '14 at 08:38
  • I can also add that I set the properties of QFrame as follow (I am using the designer of qtcreator): frameshape = NoFrame, frameShadow=Plain, lineWidth=0 and midLineWidth=0. Maybe it can help. – Lorenzo Oct 28 '14 at 08:42
  • I also set the layoutBottomMargin=0, but it has not affects on the space between the scrollbar and the content. – Lorenzo Oct 28 '14 at 08:45
  • @Lorenzo I did a small test and for me setting `layoutBottomMargin` to `0` removes the space. This is my layout: http://i.imgur.com/x9yYS96.png and this is the result http://i.imgur.com/SF9UkVh.png. What is different between your setup and mine? Maybe there are some more containers involved, could you share also the widget structure? – Iuliu Oct 28 '14 at 10:06
  • Here is my widget structure: http://i57.tinypic.com/2ec2dsy.png. Hope it can help. – Lorenzo Oct 28 '14 at 14:13
  • @Lorenzo Have you tried setting the `layoutBottomMargin` for `scrollAreaWidgetContents` to `0`? If it doesn't work I recommend trying to set the margins to 0 for *ALL* layouts in your form. This way you will be able to check if the layouts margins is the problem or not. If after you set all the margins to 0 the problem gets fixed then you just need to find which layout is responsible for the extra space. A feedback on this approach would be helpful. – Iuliu Oct 28 '14 at 14:24
  • I tried, but there is no way I can remove that space. Structure: http://i.imgur.com/QRNRol5.png Result: http://i.imgur.com/5dECUbL.png. I set all margins of all layout containers to 0, but nothing seems to work. :( – Lorenzo Oct 28 '14 at 14:53
  • Also tried a very simple layout like yours, same problem: http://imgur.com/7ltgKYE,oLcUqRZ#1 and structure: http://imgur.com/7ltgKYE,oLcUqRZ#0 – Lorenzo Oct 28 '14 at 15:44
  • Have you tried with negative padding/margin from both `QSS` or from `C++`? – Iuliu Oct 28 '14 at 16:06