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. paint on qslider

paint on qslider

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

    i subclassed QMainWindow and have a QSlider in the class (as a member), it indicates the level of zoom (something in %). everything works and is fine with it, only i want to paint a line (or i don't know how to call it in english) for the default value that is set, so that when the value of slider changes, that line will be visible. something like this:
    alt text
    i've read that i can subclass QSlider and override its paintEvent() but i don't want to do that. is there any other way?

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

      Hi
      Subclassing is the way to do it.
      Why dont u want to do that?

      You can still use Designer etc if thats the issue.

      That said, you might be able to do something using event filters but its messy at best.

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

        i didn't want to subclass because the paintEvent() is really the only thing "extra" that i'm gonna need from it. but if it's the right way i'll do it

        mrjjM 1 Reply Last reply
        0
        • U user4592357

          i didn't want to subclass because the paintEvent() is really the only thing "extra" that i'm gonna need from it. but if it's the right way i'll do it

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

          @user4592357
          Well i can relate to that as i wanted to draw some extra info on the widgets and did not want to subclass all of them so i tried to do it from outside but since your are not allowed to use QPainter outside paintevent it was not really working.

          So for one widget, sub classing cant be beat, code size wise at least. If you do inline style
          and put in mainwindow.h , its not super involving.

          #include <QSlider>
          #include <QPainter>
          class MySlider : public QSlider {
              Q_OBJECT
            public:
              explicit MySlider(QWidget *parent = nullptr) : QSlider(parent) {}    
            protected:
              void paintEvent(QPaintEvent *event) override {
                  QSlider::paintEvent(event);
                  QPainter p(this);
                  p.drawLine(15, 0, 15, 200);
              }
          };
          

          alt text

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

            hi, sorry for the late reply.

            that's exactly what i had done already. i also need have my slider work with jumps. i looked at this answer. actually, the code posted in here works. but it doesn't work at first or second times but rather after i click the slider tick a few times.

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

              please help! (read my previous post)

              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