PDA

View Full Version : vertical scrollbar width



drkbkr
12th June 2007, 20:13
Hi,

I was wondering if anyone had suggestions for how to increase the width of a vertical scrollbar on a QScrollArea. I've tried something like:
scrollArea->verticalScrollBar()->setMinimumWidth(someInt) and adding a corner widget with minimum width set to some big value, but they have no effect.

It sounds like style sheets can be used in 4.3, but unfortunately, I'm using 4.2 and there is no mention of scrollbars in the list of stylable widgets for that version.

I suspect that this can be accomplished using a subclass of QStyle, but I'm trying to avoid that route.

Any help is greatly appreciated.

Thanks,
Derek

marcel
12th June 2007, 20:18
Subclass QScrollBar and override sizeHint and minimumSizeHint. Then set your custom scroll bar to the scroll area.

Regards

drkbkr
12th June 2007, 21:09
My class:


class CScrollBar : public QScrollBar
{
public:
CScrollBar(QWidget * parent): QScrollBar(parent) {}

protected:
QSize sizeHint() { return QSize(55, 22); }

QSize minimumSizeHint() { return QSize(55, 22); }
};

and then in my code:


pendingPane->setVerticalScrollBar(new CScrollBar(pendingPane));

Seems OK to me, but the only effect is to make the scrollbar invisible (and no bigger).

And no, those are not the sizes I ultimately want, but I figured it would be noticable.

Derek

wysota
13th June 2007, 01:06
Do you want to increase the size of every scroll bar or just one? Because it might be simpler to implement a proxy style that would just return an increased pixel metric for the proper enum (QStyle::PM_ScrollBarExtent).

marcel
13th June 2007, 04:53
:)
Yes, but the only problem is that sizeHint and minimumSizeHint are virtual public and const in QWidget, not virtual protected.

Regards

drkbkr
13th June 2007, 14:50
Yes, but the only problem is that sizeHint and minimumSizeHint are virtual public and const in QWidget, not virtual protected.

New class:



class CScrollBar : public QScrollBar
{
public:
CScrollBar(QWidget * parent): QScrollBar(parent) {}

QSize sizeHint() { return QSize(55, 22); }

QSize minimumSizeHint() { return QSize(55, 22); }
};

Result is the same however. The scrollbar is invisible, and the space it would have been taking up is no bigger.

Derek

drkbkr
13th June 2007, 14:58
Do you want to increase the size of every scroll bar or just one? Because it might be simpler to implement a proxy style that would just return an increased pixel metric for the proper enum (QStyle::PM_ScrollBarExtent).

It would be for all of them.

I know I was reading recently about proxy styles, but now can't find the information. Can you point me to something about that?

Thanks,
Derek

drkbkr
13th June 2007, 15:03
Never mind. I found the information I had before in the Qt Centre Wiki.

Derek

jpn
13th June 2007, 15:18
New class:



class CScrollBar : public QScrollBar
{
public:
CScrollBar(QWidget * parent): QScrollBar(parent) {}

QSize sizeHint() { return QSize(55, 22); }

QSize minimumSizeHint() { return QSize(55, 22); }
};

Result is the same however. The scrollbar is invisible, and the space it would have been taking up is no bigger.
By the way, these do still not match the signatures of QWidget::sizeHint() and QWidget::minimumSizeHint(). They should be const methods. You're not overriding but overloading and therefore these methods never get called.

drkbkr
13th June 2007, 15:23
Thanks.

That makes them bigger, but they're still not visible, just a blank area on the right side of the scroll area.

Any ideas?

drkbkr
13th June 2007, 16:11
I tried a proxy style, using the following pixel metric method in the header file:


int pixelMetric(PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0) const
{
if (metric == PM_ScrollBarExtent)
{
qDebug("RETURNING SIZE FOR SCROLL BAR");
return 45;
}
else if(metric == PM_ScrollBarSliderMin)
{
qDebug("RETURNING MIN HEIGHT FOR SLIDER\n");
return 500;
}

return ProxyStyle::pixelMetric(metric, option, widget);
}

I see both qDebug statements many times but the returned values do not seem to be honored.

I remember that when I was trying to adjust the height of tabs in a tab widget, I looked at the code for the tab widget and tab bar classes and there was comment indicating that tab widget would ignore any attempts to resize the bar and would always make it as small as it could. Maybe this is another case like that.

Derek

jpn
13th June 2007, 16:59
int MyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
{
if (metric == PM_ScrollBarExtent)
return 45;
return ProxyStyle::pixelMetric(metric, option, widget);
}

QSize MyStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
{
if (type == QStyle::CT_ScrollBar)
return contentsSize;
return ProxyStyle::sizeFromContents(type, option, contentsSize, widget);
}

drkbkr
13th June 2007, 17:17
Well, that changes the size of the area that the scroll bar should be using, but the scroll bar is still the same size, aligned left in that area.

jpn
13th June 2007, 17:23
Which style are you using? That works fine for me with plastique style as a base. Are you sure you don't have "left overs" somewhere in your code?

Edit: Seems to work with windows and cleanlooks styles too.

drkbkr
13th June 2007, 18:00
I'm using plastique as well.

For the record, it's Qt 4.2.1 on Ubuntu.

Here's a compilable example, and the results that I see on my laptop.

Derek

jpn
13th June 2007, 18:06
Sorry, I don't have any other version than 4.3.0 installed on this machine so I cannot test with others but I can confirm that at least with 4.3.0 it's fine.. :)

drkbkr
13th June 2007, 18:09
Sorry, I don't have any other version than 4.3.0 installed on this machine so I cannot test with others but I can confirm that at least with 4.3.0 it's fine.. :)

My example is fine? Or your test is? I don't think I missed anything in my example, but who knows...

jpn
13th June 2007, 18:17
My example is fine? Or your test is? I don't think I missed anything in my example, but who knows...
Yours is fine, too. Just for for the records, I'm running Xubuntu 7.04 on this crappy old machine I've got. :)

drkbkr
13th June 2007, 18:20
Thanks for your help.

Building 4.3 right now.

drkbkr
13th June 2007, 19:08
Works as expected with 4.3.0

Derek

MarkoSan
30th May 2008, 09:43
Nice thread, but how do I "inherit" parent's widget (QTableView's in my case) and set it up as subclassed scrollbar height?

wysota
30th May 2008, 10:51
Would you care to explain what you mean?

MarkoSan
30th May 2008, 13:22
I would like to achieve that QScrollbar's height is alwasy same as it's parent's object height (in my case, the parent is QTableView).

jpn
30th May 2008, 13:30
Isn't like that, out of the box?

MarkoSan
30th May 2008, 13:32
What do you mean out of the box? If that is default, why then when reimplementing size do I need width (y) param?

And how to fill scrollbar with some texture?

wysota
31st May 2008, 07:09
If that is default, why then when reimplementing size do I need width (y) param?
Could you provide a snippet of code demonstrating what you mean?


And how to fill scrollbar with some texture?

Use stylesheets.