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. Custom slider initialization and interval problem

Custom slider initialization and interval problem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 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.
  • D Offline
    D Offline
    dnadave
    wrote on last edited by
    #1

    I finally have my subclass of QSlider working and have it linked to a QDSpinBox. My problem is now that despite having the two linked using connect, the initial values given to the QDSpinBox are not passed to the QDSlider (my subclass of QSlider).

    Also, the step interval for my QDSlider is supposed to be set at 5 from what I entered in using QtDesigner, but it appears to move at intervals of 1.

    Here's the relevant code:

    qdslider.h:

    @
    #include <QSlider>

    class QDSlider : public QSlider
    {
    Q_OBJECT
    public:
    explicit QDSlider();
    explicit QDSlider( QWidget * );
    explicit QDSlider( Qt::Orientation , QWidget * );
    signals:
    void valueChanged( double );
    void sliderMoved( double );
    private slots:
    void setValue( double );
    void valueDChanged( int );
    };
    @

    qdslider.cpp:

    @
    #include "qdslider.h"

    QDSlider::QDSlider():QSlider() {}
    QDSlider::QDSlider( QWidget *parent = 0 ):QSlider( parent ) {}
    QDSlider::QDSlider( Qt::Orientation orientation , QWidget *parent = 0 ):QSlider( orientation , parent ) {}

    void QDSlider::setValue( double value )
    {
    int ivalue = value * 10;
    emit QSlider::setValue( ivalue );
    }

    void QDSlider::valueDChanged( int value )
    {
    double dvalue = (double)value / 10.0;
    emit valueChanged( dvalue );
    }
    @

    connect code in main:

    @
    // Connect the two slider slots
    QObject::connect( ui->eptErrorHSlider , SIGNAL( valueChanged( int ) ) ,
    ui->eptErrorHSlider , SLOT( valueDChanged( int ) ) );
    QObject::connect( ui->eptErrorDSpin , SIGNAL( valueChanged( double ) ) ,
    ui->eptErrorHSlider , SLOT( setValue( double ) ) );
    QObject::connect( ui->eptErrorHSlider , SIGNAL( sliderMoved( double ) ) ,
    ui->eptErrorDSpin , SLOT( setValue( double ) ) );
    QObject::connect( ui->eptErrorHSlider , SIGNAL( valueChanged( double ) ) ,
    ui->eptErrorDSpin , SLOT( setValue( double ) ) );
    QObject::connect( ui->eptPowerHSlider , SIGNAL( valueChanged( int ) ) ,
    ui->eptPowerHSlider , SLOT( valueDChanged( int ) ) );
    QObject::connect( ui->eptPowerDSpin , SIGNAL( valueChanged( double ) ) ,
    ui->eptPowerHSlider , SLOT( setValue( double ) ) );
    QObject::connect( ui->eptPowerHSlider , SIGNAL( sliderMoved( double ) ) ,
    ui->eptPowerDSpin , SLOT( setValue( double ) ) );
    QObject::connect( ui->eptPowerHSlider , SIGNAL( valueChanged( double ) ) ,
    ui->eptPowerDSpin , SLOT( setValue( double ) ) );
    @

    Any ideas on what I'm doing wrong?

    Dave H

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      I have found some bugs, but I am not sure, whether they help:

      @
      void QDSlider::setValue( double value )
      {
      int ivalue = value * 10;
      emit QSlider::setValue( ivalue );
      }
      @

      here emit is wrong, setValue is not a signal.

      Why do you connect the signals of your base class to your slot from outside and not within your constructor? That makes much more sense

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        I personally would create a new custom widget, containing the slider and the spin box, with it's own set of signals and slots and "hide" the internal connections between the both in the custom widget. You can even make a plugin to use the new custom widget in Qt Designer.

        http://www.catb.org/~esr/faqs/smart-questions.html

        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