1

Recently I came to SO in this question asking how could I get my hands on a QComboBox' QScrollBar in order to change its thickness. After reading the replies, I tried Marco A. solution for my Qt Embedded application and it didn't worked. Then, for test, I changed the compilation environment to Desktop and the fix worked!

So essentially my problem is that when I try to change a QComboBox's QScrollBar width in Qt for Embedded Linux (ARM), nothing happens, but if I compile the exact same code for Qt for Desktop, it works. The following is the code I'm using for tests:

QAbstractItemView* poView = ui->comboBox->view();
QScrollBar* poBar = poView->verticalScrollBar();
poBar->setStyleSheet("width: 50px;");

and there is another code that does the same, but shows the same problem:

ui->comboBox->setStyleSheet("QScrollBar:vertical { width: 50px; }");

With comboBox being declared in the ui form in Qt Designer (inside Qt Creator).

Qt versions are the same for Desktop and Qt for Embedded Linux (4.8.5). Another thing I found strange (but should have nothing to do with it) is that compiling the same code again for Desktop shows a QComboBox with a Windows XP style, while for Embedded the Plastique style is used (I notice that quite clearly due to Plastique showing three instead of two buttons to scroll the scroll bar).

So what could be happening? How may I solve this problem?

Community
  • 1
  • 1
Momergil
  • 2,213
  • 5
  • 29
  • 59

2 Answers2

1

I noticed the same symptoms. In Qt a lot of the drawing, I understand, has been delegated to the styles, and the Plastique style seems to have a bug in that it doesn't seem to draw a vertical scroll bar in the right coordinates if it doesn't have the default size. So if you do this:

QScrollBar:vertical
{
    min-width: 35px;
    width: 35px;
}

you end up with the symptoms you described. But, AFAICS there's something wrong with the handling of margins as well! If you play around with the margins, e.g. like this:

QScrollBar:vertical
{
    min-width: 35px;
    width: 35px;
    margin-right: 35px;
}

you should be able to work around the bug.

Worked for me at least.

path
  • 26
  • 3
  • Thanks for the typ. In fact, the solution works pretty well when it comes to controlling the width of the scroll bar. The problem is now that the control ever it gets bugged: if I click in any part of the scroll bar but the down arrow, the bar goes up! have you any idea how to fix that? – Momergil Mar 25 '15 at 20:26
0
poBar->setMinimumWidth(50);
poBar->setMaximumWidth(50);

I tried it with PyQt5, QT5 in Python3-syntax, it customizes the width of the Scrollbar on Linux (Ubuntu 14.04) as well as on windows7

a_manthey_67
  • 4,046
  • 1
  • 17
  • 28
  • thanks for the reply, but I already tested this solution before and both for Ubuntu and Embedded Linux it doesn't work: while it does change the width of the bar, it doesn't change the width of the space where the bar is located, so at the end the resized QScrollBar appears cut and with the same useful area as before. Sorry for not showing a print, but as I think I sad ubuntu is not letting me do a printscreen with the QComboBox's list visible. – Momergil Oct 06 '14 at 12:48
  • @Momergil: did you try pobar->setGeometry()? – a_manthey_67 Oct 06 '14 at 13:08