PDA

View Full Version : QListView's scrollbar stylesheet



luochen601
8th September 2010, 10:23
Hi everyone,

How to change the listview's scrollbar appearance?
I have to change the background and up&down arrow of scrollbar.
Example code will help me a lot. thanks.

kemp
8th September 2010, 13:16
http://doc.trolltech.com/4.6/stylesheet-examples.html#customizing-qscrollbar

kemp
8th September 2010, 13:20
ListView->horizontalScrollBar()->setStyleSheet("QScrollBar:horizontal {border: 2px solid grey;background: #32CC99;height: 15px;margin: 0px 20px 0 20px;}");

luochen601
9th September 2010, 04:21
ListView->horizontalScrollBar()->setStyleSheet("QScrollBar:horizontal {border: 2px solid grey;background: #32CC99;height: 15px;margin: 0px 20px 0 20px;}");

Thansk, it works.
But the style is limited to change color, could not support image. The following code do not work as expect.
ui->listView->verticalScrollBar()->setStyleSheet("QScrollBar:vertical {width: 15px; background-image: url(:/img/scroll_bg.png);}; QScrollBar::handle:vertical {image:url(:/img/scroll_handle.png)}");

kemp
9th September 2010, 06:34
You cannot support image for the QScrollBar with stylesheet. You can subclass the scrollbar and paint it yourself in the paintevent.