Scroll bar of QListWidget



  • Hello, everyone.

    As we know that the scroll bar will appear if there are more items than the list widget could show.

    I don't like the appearance of the scroll bar, so can I inherit the scroll of the QListWidget so that I could customize my own scroll bar?

    and how to do it.

    thanks for suggestions.

    best regards
    hisong.



  • use QSS



  • Hi, Alexander Kuchumov
    would you show me how to define the scroll bar of QListWidget by using QSS.

    or just give me some demo code ? thanks very much.



  • You can use css to change the apperance of the scroll bar. Set the stylesheet for the QListWidget. Here is the link from Qt labs blog "QScrollBar CSS":http://labs.qt.nokia.com/2007/06/12/styling-qprogressbar-and-qscrollbar/



  • You can use your own QScrollBar. You can subclass QScrollBar and set it on the QScrollArea that QListWidget inherits. This will allow you to totally develop your own scroll bar, but also makes you have to draw it yourself (depending on how far you customize it).

    There are other ways though. Probably the easiest one is to use Qt's CSS-for-widgets. I guess that what QSS means. The idea is the same as with CSS, only it allows you to style Qt Widgets. There is an "example":http://doc.qt.nokia.com/4.7/stylesheet-examples.html#customizing-qscrollbar in the Qt docs.

    Yet another way is to develop your own (proxy) QStyle. That allows you implement a reusable style implementation for your scroll bar. Another approach is basically not to use QListWidget at all, but use a QAbstractItemModel (or a subclass of that) and use a QML view with a ListView element to completely restyle your view with QML. It doesn't come with a scrollbar at all by default, but it is easy to make one appear as you see fit.

    As you see: there are many options. But since you don't really specify what you really want to achieve, it is hard to give solid guidance. I guess the style sheet option is the best avenue to try first.



  • Or simply remember that QListWidget is-a QAbstractScrollArea, so you can set your own QScrollBar with setVerticalScrollBar().

    [edited to add]: Ok, simply wipe out this coment. Andre explained everything very well :-)



  • Hi,AS.Sri

    how to indicate the scroll bar of the QListWidget?

    can like this
    @
    listWidget->setStyleSheet(QListWidget::scrollbar{my own code});
    @

    ?



  • [quote author="hisong1988" date="1293021621"]Hi,AS.Sri

    how to indicate the scroll bar of the QListWidget?

    can like this
    @
    listWidget->setStyleSheet(QListWidget::scrollbar{my own code});
    @

    ?[/quote]
    Did you try reading the documentation on Qt widget style sheets? It has a whole section on selectors you can use.



  • As Andre mentioned you can use any selector but,

    @listWidget->setStyleSheet("selector{my own code}; selector{my own code};............. ");@

    you don't have to specify QListWidget.



  • @QListWidget list = new QListWidget();
    list->setStyleSheet("
    {background-color: white; background-image: url(:/Kres/resources/bg01.png); background-attachment: scroll; }");@

    maybe this would help someone :D


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.