Add || sign on top of the ScrollBar



  • Hi All,

    I am trying to add || sign on top of the ScrollBar in the left and right most of the ScrollBar as of now I am not able to figure out how to put any sign on top of the ScrollBar.
    link text --> Reference Image

    I have attached the reference Image. how should I proceed pls let me know for the same.

    And on top of that I have to capture the the hover and drag event for the future.

    So pls help me out of this.

    Thanks
    Praveen


  • Qt Champions 2017

    hi
    You can style a scrollbar using stylesheets
    http://doc.qt.io/qt-5/stylesheet.html
    http://blog.qt.io/blog/2007/06/12/styling-qprogressbar-and-qscrollbar/
    Maybe you can get the look you want from this.


  • Moderators

    @praveen0991kr

    void MyScrollBar::paintEvent( QPaintEvent* event )
    {
         QScrollBar::paintEvent( event );
    
         QPainter p(this);
         QStyleOptionSlider opt;
         initStyleOption(&opt);
         opt.subControls = QStyle::SC_All;
    
         QRect handleRect = this->style()->subControlRect( QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSlider, this );
    
         // do your painting inside the handleRect
    }
    

    You can move the code to retrieve the rect to a separate method and reuse it to determine if the hover/move event is inside the rect, etc.



  • @raven-worx

    Its worked as per Requirement the code as follows :

    void paintEvent(QPaintEvent* event)
    	{
    		QScrollBar::paintEvent(event);
    
    		QPainter p(this);
    		QStyleOptionSlider opt;
    		initStyleOption(&opt);
    		opt.subControls = QStyle::SC_All;
    
    		QRect handleRect = this->style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSlider, this);
    		p.drawText(handleRect, Qt::AlignLeft,"  ||");
    		p.drawText(handleRect, Qt::AlignRight,"||  ");
    		p.drawRect(handleRect);
    	}
    

    http://i.stack.imgur.com/Acg62.png --> Image attached with the result

    Next I have to Implement hover/Pressed event on the painter ; how should I proceed for the same.

    Thanks
    Praveen


Log in to reply
 

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