Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved slider and plus/minus signs

    General and Desktop
    slider boundingrect
    2
    9
    2618
    Loading More Posts
    • 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
      user4592357 last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • U
          user4592357 last edited by

          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);
          }
          
          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @user4592357 last edited by

            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 Reply Quote 0
            • U
              user4592357 last edited by

              that didn't help.

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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @user4592357 last edited by mrjj

                @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 Reply Quote 0
                • U
                  user4592357 last edited by

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

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @user4592357 last edited by 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 1 Reply Last reply Reply Quote 3
                    • U
                      user4592357 @mrjj last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post