PDA

View Full Version : horizontalSlider and hidden widgets



smemamian
29th June 2013, 21:52
hi

i want that when horizontalSlider will change, widgets be Apparent or hidden .


#include "addaward.h"
#include "ui_addaward.h"
#include "stringclass.h"

Addaward::Addaward(QWidget *parent) :
QDialog(parent),
ui(new Ui::Addaward)
{
ui->setupUi(this);

ui->label2->setHidden(true);
ui->lineEdit_2->setHidden(true);
// "a" is a int type
a = ui->horizontalSlider->value();
setVisiblity();
}

Addaward::~Addaward()
{
delete ui;
}

void Addaward::setVisiblity()
{
switch(a)
{
case 2:
{
ui->label2->setHidden(false);
ui->lineEdit_2->setHidden(false);
} break ;

}
}

But it does not work !

ChrisW67
29th June 2013, 22:16
There are no widgets on the screen during the constructor, so the slider has whatever it default value is (because the user cannot interact with it) and you are setting the widgets initial visibility only. Since you also do nothing to ensure that changes to the slider value trigger a rethink of the widget visibility after they are visible then their initial visibilty stays unchanged.

You need to look at using a signal from the slider and a slot to update the visibility.

BTW: "It doesn't work" is a very poor description of the problem.