Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: vertical scrollbar width

  1. #1
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default vertical scrollbar width

    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:
    Qt Code:
    1. scrollArea->verticalScrollBar()->setMinimumWidth(someInt)
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Subclass QScrollBar and override sizeHint and minimumSizeHint. Then set your custom scroll bar to the scroll area.

    Regards

  3. #3
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    My class:

    Qt Code:
    1. class CScrollBar : public QScrollBar
    2. {
    3. public:
    4. CScrollBar(QWidget * parent): QScrollBar(parent) {}
    5.  
    6. protected:
    7. QSize sizeHint() { return QSize(55, 22); }
    8.  
    9. QSize minimumSizeHint() { return QSize(55, 22); }
    10. };
    To copy to clipboard, switch view to plain text mode 

    and then in my code:

    Qt Code:
    1. pendingPane->setVerticalScrollBar(new CScrollBar(pendingPane));
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vertical scrollbar width

    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).

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width


    Yes, but the only problem is that sizeHint and minimumSizeHint are virtual public and const in QWidget, not virtual protected.

    Regards

  6. #6
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Quote Originally Posted by marcel View Post
    Yes, but the only problem is that sizeHint and minimumSizeHint are virtual public and const in QWidget, not virtual protected.
    New class:

    Qt Code:
    1. class CScrollBar : public QScrollBar
    2. {
    3. public:
    4. CScrollBar(QWidget * parent): QScrollBar(parent) {}
    5.  
    6. QSize sizeHint() { return QSize(55, 22); }
    7.  
    8. QSize minimumSizeHint() { return QSize(55, 22); }
    9. };
    To copy to clipboard, switch view to plain text mode 

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

    Derek

  7. #7
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Quote Originally Posted by wysota View Post
    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

  8. #8
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Never mind. I found the information I had before in the Qt Centre Wiki.

    Derek

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: vertical scrollbar width

    Quote Originally Posted by drkbkr View Post
    New class:

    Qt Code:
    1. class CScrollBar : public QScrollBar
    2. {
    3. public:
    4. CScrollBar(QWidget * parent): QScrollBar(parent) {}
    5.  
    6. QSize sizeHint() { return QSize(55, 22); }
    7.  
    8. QSize minimumSizeHint() { return QSize(55, 22); }
    9. };
    To copy to clipboard, switch view to plain text mode 

    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.
    J-P Nurmi

  10. #10
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    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?

  11. #11
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    I tried a proxy style, using the following pixel metric method in the header file:

    Qt Code:
    1. int pixelMetric(PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0) const
    2. {
    3. if (metric == PM_ScrollBarExtent)
    4. {
    5. qDebug("RETURNING SIZE FOR SCROLL BAR");
    6. return 45;
    7. }
    8. else if(metric == PM_ScrollBarSliderMin)
    9. {
    10. qDebug("RETURNING MIN HEIGHT FOR SLIDER\n");
    11. return 500;
    12. }
    13.  
    14. return ProxyStyle::pixelMetric(metric, option, widget);
    15. }
    To copy to clipboard, switch view to plain text mode 

    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

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: vertical scrollbar width

    Qt Code:
    1. int MyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
    2. {
    3. if (metric == PM_ScrollBarExtent)
    4. return 45;
    5. return ProxyStyle::pixelMetric(metric, option, widget);
    6. }
    7.  
    8. QSize MyStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
    9. {
    10. if (type == QStyle::CT_ScrollBar)
    11. return contentsSize;
    12. return ProxyStyle::sizeFromContents(type, option, contentsSize, widget);
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 13th June 2007 at 17:05. Reason: Removed a confusing prefix ;)
    J-P Nurmi

  13. #13
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    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.

  14. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: vertical scrollbar width

    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.
    Attached Images Attached Images
    J-P Nurmi

  15. #15
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    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
    Attached Images Attached Images
    Attached Files Attached Files

  16. #16
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: vertical scrollbar width

    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..
    J-P Nurmi

  17. #17
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Quote Originally Posted by jpn View Post
    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...

  18. #18
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: vertical scrollbar width

    Quote Originally Posted by drkbkr View Post
    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.
    Attached Images Attached Images
    J-P Nurmi

  19. #19
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Thanks for your help.

    Building 4.3 right now.

  20. #20
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: vertical scrollbar width

    Works as expected with 4.3.0

    Derek

Similar Threads

  1. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15
  2. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34
  3. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.