December 12, 2011

stima_ua stima_ua
Lab Rat
72 posts

QScrollBar and handle height

 

I can not set handle height. My css:

  1. QScrollBar:vertical {
  2.       border-image: url(:/images/scroll_bg.png);
  3.       width: 20px;
  4.       margin: 5px 5px 52px 0px;
  5. }
  6.  
  7. QScrollBar::handle:vertical {
  8.      background: url(:/images/handle.png);
  9.      height: 5px;
  10.      width: 5px;
  11.      /*border-radius: 3px;*/
  12. }
  13.  
  14. QScrollBar::add-page:vertical {
  15.  border-image: url(:/images/scroll_add_page.png);
  16. }
  17.  
  18. QScrollBar::sub-page:vertical  {
  19.  margin: 5px 2px 0px 2px;
  20.  border-image: url(:/images/scroll_sub_page.png);
  21. }
  22.  
  23. QScrollBar::add-line:vertical {
  24.  border-image: url(:/images/add_line.png);
  25.  height: 26px;
  26.  margin: 0px 5px 5px 0px;
  27.  subcontrol-origin: margin;
  28. }
  29.  
  30. QScrollBar::sub-line:verticall {
  31.  border-image: url(:/images/sub_line.png);
  32.  height: 26px;
  33.  margin: 0px 5px 26px 0px;
  34.  subcontrol-position: bottom;
  35.  subcontrol-origin: margin;
  36. }
  37.  
  38. QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
  39.       background: none;
  40.   }

5 replies

December 13, 2011

stima_ua stima_ua
Lab Rat
72 posts

mmm…
How can I get handle from scrollbar to set him fixed size

December 13, 2011

Eddy Eddy
Area 51 Engineer
1612 posts

The main idea of the handle height is that it’s height represents a percentage of the total height it is scrolling on.

Eg if the actual size is twice the scroll area then the handle height would be half the visible area.

Why would you want to change this behaviour? What is your specific use case?

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

December 13, 2011

fluca1978 fluca1978
Lab Rat
529 posts

I agree with Eddy, changing the default behavior of a scroll bar can confuse the user. However I would try to change values into the QStyleOptionSlider [doc.qt.nokia.com] to see if this trick works for drawing the scroll bar. It is just an idea.

December 14, 2011

stima_ua stima_ua
Lab Rat
72 posts

thnx but i dont know how :(

  1. void TreeWidget::paintEvent(QPaintEvent *event)
  2. {
  3.     QTreeWidget::paintEvent(event);
  4.     QPainter painter(this);
  5.     QStyleOptionSlider option;
  6.  
  7.     option.initFrom(this);
  8.    
  9.     /*????*/
  10.  
  11.     style()->drawComplexControl(QStyle::CC_Slider, &option, &painter, this);
  12. }

December 14, 2011

Eddy Eddy
Area 51 Engineer
1612 posts

Just a thought: why not use a QSlider [doc.qt.nokia.com]?

Sounds this is what you want and you can use stylesheet to change the look of the handle.

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

 
  ‹‹ ComboBox filled using a model      error while loading QtNetwork4.dll ››

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