Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7677551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:26:52+00:00 2026-05-31T17:26:52+00:00

I have a Qt dialog and there is a slider in it, when the

  • 0

I have a Qt dialog and there is a slider in it, when the dialog is initialized the slider will be set a value. In order to remind the user what is the default value, I want to add a mark to the slider, just draw a line or a triangle above the handle. Here, the slider should be of QSlider type, that means I can’t implement a customized control derived from QSlider. Is there any way to realize it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:26:53+00:00Added an answer on May 31, 2026 at 5:26 pm

    I’m not clear why you can’t derive a control from QSlider. You can still treat it like a QSlider, just override the paintEvent method. The example below is pretty cheesy, visually speaking, but you could use the methods from QStyle to make it look more natural:

    #include <QtGui>
    
    class DefaultValueSlider : public QSlider {
      Q_OBJECT
    
     public:
      DefaultValueSlider(Qt::Orientation orientation, QWidget *parent = NULL)
        : QSlider(orientation, parent),
          default_value_(-1) {
        connect(this, SIGNAL(valueChanged(int)), SLOT(VerifyDefaultValue(int)));
      }
    
     protected:
      void paintEvent(QPaintEvent *ev) {
        int position = QStyle::sliderPositionFromValue(minimum(),
                                                       maximum(),
                                                       default_value_,
                                                       width());
        QPainter painter(this);
        painter.drawLine(position, 0, position, height());
        QSlider::paintEvent(ev);
      }
    
     private slots:
      void VerifyDefaultValue(int value){
        if (default_value_ == -1) {
          default_value_ = value;
          update();
        }
      }
    
     private:
      int default_value_;
    };
    
    int main(int argc, char *argv[]) {
      QApplication app(argc, argv);
    
      DefaultValueSlider *slider = new DefaultValueSlider(Qt::Horizontal);
      slider->setValue(30);
    
      QWidget *w = new QWidget;
      QVBoxLayout *layout = new QVBoxLayout;
      layout->addWidget(slider);
      layout->addStretch(1);
      w->setLayout(layout);
    
      QMainWindow window;
      window.setCentralWidget(w);
      window.show();
    
      return app.exec();
    }
    
    #include "main.moc"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any example on how to implement a simple login page/dialog? I have
I have a dialog preference with a button on it that I want to
I have a dialog in Java that presents ~ 15 checkboxes to the user.
I have a dialog box that has settings associated with it. When the user
I have an MFC dialog in which there are two radio buttons. I have
I have a dialog application in which I want to have clickable menu items
I have a main dialog and on that dialog there is a button. When
I have en dialog box where there is an CKEditor inside. But i can't
I have a dialog box in which there are tabs. In one of the
i have a dialog box, but some how there is an unknown background image.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.