December 22, 2010

hisong1988 hisong1988
Lab Rat
72 posts

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.

 Signature 

I am still searching for….

9 replies

December 22, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
380 posts

use QSS

December 22, 2010

hisong1988 hisong1988
Lab Rat
72 posts

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.

 Signature 

I am still searching for….

December 22, 2010

Srinidhi M Srinidhi M
Lab Rat
43 posts

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 [labs.qt.nokia.com]

December 22, 2010

Andre Andre
Robot Herder
6420 posts

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 [doc.qt.nokia.com] 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.

December 22, 2010

peppe peppe
Ant Farmer
1029 posts

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

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

December 22, 2010

hisong1988 hisong1988
Lab Rat
72 posts

Hi,AS.Sri

how to indicate the scroll bar of the QListWidget?

can like this

  1. listWidget->setStyleSheet(QListWidget::scrollbar{my own code});

?

 Signature 

I am still searching for….

December 22, 2010

Andre Andre
Robot Herder
6420 posts

hisong1988 wrote:
Hi,AS.Sri

how to indicate the scroll bar of the QListWidget?

can like this

  1. listWidget->setStyleSheet(QListWidget::scrollbar{my own code});

?


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

December 22, 2010

Srinidhi M Srinidhi M
Lab Rat
43 posts

As Andre mentioned you can use any selector but,

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

you don’t have to specify QListWidget.

September 3, 2011

abah abah
Lab Rat
1 posts

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

maybe this would help someone :D

 
  ‹‹ Problem in QDialog Full Screen with Exec() ?      How to use ICU with QT sql ››

You must log in to post a reply. Not a member yet? Register here!