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