Cant Reset slider position



  • Hi there,
    Here is my issue: when I reset the position of my slider it acts like if it's been moved while I just press on it.
    Here is a part of my code:
    @
    WinA::WinA(FenPrincipale *FenPr, QWidget *parent) : QWidget(parent)
    {

    Couleur = new QLabel;
    Hierar = new HierarchItem (FenPr, this);

    boutonItem = new QSlider(Qt::Horizontal,this);
    boutonItem->setGeometry(146,121,20,4);
    boutonItem->setRange(0,100);
    boutonItem->setValue(40);

    labelH = new QLabel(Hierar);
    labelH->move(71,102);
    labelH->setStyleSheet("color: #C9C9C9;");
    labelH2 = new QLabel(Hierar);
    labelH2->move(200,102);
    labelH2->setStyleSheet("color: #C9C9C9;");

    QObject::connect(boutonItem, SIGNAL(sliderPressed()), this, SLOT(DisplayItem()));
    QObject::connect(boutonItem, SIGNAL(valueChanged(int)), this, SLOT(SelectItem(int)));

    }

    void WinA::SelectItem(int posbH)
    {
    if(posbH==40)
    {
    //QObject::disconnect(boutonItem, SIGNAL(sliderReleased()), this, SLOT(TraitementLabelH()));
    //QObject::disconnect(boutonItem, SIGNAL(sliderReleased()), this, SLOT(TraitementLabelH2()));
    labelH->setStyleSheet("color: #C9C9C9;");
    labelH2->setStyleSheet("color: #C9C9C9;");
    }

    if(posbH>40)
    {
    labelH->setStyleSheet(""+Couleur->text()+"");
    labelH2->setStyleSheet("color: #C9C9C9;");
    }

    if(posbH<40)
    {
    labelH->setStyleSheet("color: #C9C9C9;");
    labelH2->setStyleSheet(""+Couleur->text()+"");
    }

    if(posbH>90)
    {
    QObject::connect(boutonItem, SIGNAL(sliderReleased()), this, SLOT(TraitementLabelH()));
    }

    if(posbH<10)
    {
    QObject::connect(boutonItem, SIGNAL(sliderReleased()), this, SLOT(TraitementLabelH2()));
    }

    }

    void WinA::TraitementLabelH()
    {
    this->close;
    }

    void WinA::TraitementLabelH2()
    {
    this->close;
    }

    void WinA::DisplayItem()
    {
    labelH->setText(Hierar->getlabelHier());
    labelH2->setText(Hierar->getlabelHier2());

    //Seconde Animation
    QPropertyAnimation *animation = new QPropertyAnimation(labelH, "geometry");
    animation->setDuration(153);
    animation->setStartValue(QRect(138, 102, 60, 14));
    animation->setEndValue(QRect(200, 102, 60, 14));
    animation->start(QAbstractAnimation::DeleteWhenStopped);
    
    //Seconde Animation
    QPropertyAnimation *animation2 = new QPropertyAnimation(labelH2, "geometry");
    animation2->setDuration(153);
    animation2->setStartValue(QRect(138, 102, 60, 14));
    animation2->setEndValue(QRect(71, 102, 60, 14));
    animation2->start(QAbstractAnimation::DeleteWhenStopped);
    
    QObject::connect(boutonItem, SIGNAL(sliderReleased()), this, SLOT(HideItem()));
    

    }

    void WinA::HideItem()
    {
    //Seconde Animation
    animation3 = new QPropertyAnimation(labelH, "geometry");
    animation3->setDuration(153);
    animation3->setStartValue(QRect(200, 102, 60, 14));
    animation3->setEndValue(QRect(138, 102, 60, 14));
    animation3->start(QAbstractAnimation::DeleteWhenStopped);

    QObject::connect(animation3, SIGNAL(finished()), labelH, SLOT(clear()));
    
    //Seconde Animation
    animation4 = new QPropertyAnimation(labelH2, "geometry");
    animation4->setDuration(153);
    animation4->setStartValue(QRect(71, 102, 60, 14));
    animation4->setEndValue(QRect(138, 102, 60, 14));
    animation4->start(QAbstractAnimation::DeleteWhenStopped);
    
    QObject::connect(animation4, SIGNAL(finished()), labelH2, SLOT(clear()));
    
    boutonItem->setValue(40);
    

    }
    @

    As you can notice the position of the slider is reset through HideItem().
    I forgot to mention that I use stackedwidgets in my app and this problem happens when I come back to the widget. First of all, is it the right methode to reset the position? If not, how can I reset my slider properly? Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.