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. slider and plus/minus signs
QtWS25 Last Chance

slider and plus/minus signs

Scheduled Pinned Locked Moved Unsolved General and Desktop
sliderboundingrect
9 Posts 2 Posters 3.7k Views
  • 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i have a qslider object, on the left side of which i place "-" sign, on the right side a "+" sign. on the application they appear in separate "rectangles". what's the problem here? should i reimplement slider's paintEvent?

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

      Hi
      How do you place them? QLabel?
      While you can overlay widgets to some degree, if you scale window , it often goes broke.
      So yes, painting theme will work better.

      1 Reply Last reply
      1
      • U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        but how do i actually paint that? i thought this would suffice but no:

        void Slider::paintEvent(QPaintEvent *event) {
            QPainter painter(this);
            painter.setPen(QPen(Qt::SolidPattern, 1));
            painter.drawText(-5, height() / 2, QString("-"));
            painter.drawText(width() + 5, height() / 2, QString("+"));
        
            QSlider::paintEvent(event);
        }
        
        mrjjM 1 Reply Last reply
        0
        • U user4592357

          but how do i actually paint that? i thought this would suffice but no:

          void Slider::paintEvent(QPaintEvent *event) {
              QPainter painter(this);
              painter.setPen(QPen(Qt::SolidPattern, 1));
              painter.drawText(-5, height() / 2, QString("-"));
              painter.drawText(width() + 5, height() / 2, QString("+"));
          
              QSlider::paintEvent(event);
          }
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Try move
          QSlider::paintEvent(event);
          to the top so base paints first and then you.
          else it might override.

          also drawText(-5, might not work as
          you cant paint outside the area of the widget.
          same with painter.drawText(width() + 5

          you cant have them inside the widget ?

          1 Reply Last reply
          0
          • U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            that didn't help.

            what do you mean? have a container that contains qlabel, qslider, qlabel?

            mrjjM 1 Reply Last reply
            0
            • U user4592357

              that didn't help.

              what do you mean? have a container that contains qlabel, qslider, qlabel?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @user4592357
              No, i mean draw them inside the widget. You give it x values that
              is outside the clipping area. You cannot use negative value nor bigger
              than width() to draw anything. You cannot paint outside a widget.

              Maybe i misunderstood what you mean by
              "appear in separate "rectangles"
              Sounded like you did use a layout to make a composite widget but
              wanted the +/- to overlap the slider area.

              So do you want the +/- to be over the slider area or is right next to both side fine enough?

              1 Reply Last reply
              0
              • U Offline
                U Offline
                user4592357
                wrote on last edited by
                #7

                i want "- slider +" to appear as one widget

                mrjjM 1 Reply Last reply
                0
                • U user4592357

                  i want "- slider +" to appear as one widget

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  @user4592357

                  Hehe i must ask in a stupid way :)
                  So its ok that + and minus are right next to the slider and not over it ?
                  If yes, you can just use a layout to make stick together.
                  It would appear as one widget but plus and minus would be next to the slider and not on top /overlapping it.

                  Like this ?
                  alt text

                  To make:
                  Place widget on Form
                  place label with + and slider and label with - inside widget in right order.
                  not important if they are aligned.
                  Then right click a free area of the widget and select
                  Layout menu -> Layout horizontally

                  U 1 Reply Last reply
                  3
                  • mrjjM mrjj

                    @user4592357

                    Hehe i must ask in a stupid way :)
                    So its ok that + and minus are right next to the slider and not over it ?
                    If yes, you can just use a layout to make stick together.
                    It would appear as one widget but plus and minus would be next to the slider and not on top /overlapping it.

                    Like this ?
                    alt text

                    To make:
                    Place widget on Form
                    place label with + and slider and label with - inside widget in right order.
                    not important if they are aligned.
                    Then right click a free area of the widget and select
                    Layout menu -> Layout horizontally

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #9

                    @mrjj i think i'll just write the code :p will do tomorrow and see what i get, thanks!

                    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