Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Add || sign on top of the ScrollBar
Qt 6.11 is out! See what's new in the release blog

Add || sign on top of the ScrollBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    praveen0991kr
    wrote on last edited by
    #1

    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

    raven-worxR 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      0
      • P praveen0991kr

        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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

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

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        3
        • P Offline
          P Offline
          praveen0991kr
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved