Hi,
i am interested to create a combo-box which should appear as shown below.
double_combobox.png
After "highlighting" the index_5 of first combobox i.e. "SiX_6", it should show a second combo-box near to that showing "Days".
I have created a custom widget mycombobox, which contains the 1st combobox with data 'SiX_6', i have attached the signal of this combo box on highlight to a slot defined here, which checks if the selected index is 5, and in that slot, i am creating the 2nd combobox showing days.
I am not able to see the 2nd combobox on screen.
Is the way i am proceeding is correct? or what is the way to do this type of widget?
thanks in advance.
{
Q_OBJECT
public:
explicit myComboBox
(QWidget *parent
= 0);
~myComboBox ();
signals:
public slots:
void Activate_2nd_Box(int index);
protected:
};
myComboBox
::myComboBox(QWidget *parent
) :{
dump_data << "ONE_1" << "TWO_2" << "THREE_3" << "FouR_4" << "FivE_5" << "SiX_6";
doublebox->addItems( dump_data );
connect(doublebox, SIGNAL(highlighted(int)), this, SLOT(Activate_2nd_Box(int)));
//connect(doublebox, SIGNAL(currentIndexChanged(int)), this, SLOT(Activate_2nd_Box(int)));
}
myComboBox::~myComboBox()
{
delete box;
delete label;
}
void myComboBox::Activate_2nd_Box(int index)
{
if(index == 5)
{
qDebug() << "index : "<< index << " highlighted";
data << "Sunday" << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday";
box2->addItems( data );
box2->show();
}
}
class myComboBox : public QWidget
{
Q_OBJECT
public:
explicit myComboBox(QWidget *parent = 0);
~myComboBox ();
signals:
public slots:
void Activate_2nd_Box(int index);
protected:
QComboBox *box;
QLabel *label;
};
myComboBox::myComboBox(QWidget *parent) :
QWidget(parent)
{
QStringList dump_data;
dump_data << "ONE_1" << "TWO_2" << "THREE_3" << "FouR_4" << "FivE_5" << "SiX_6";
QComboBox *doublebox = new QComboBox(this);
doublebox->addItems( dump_data );
connect(doublebox, SIGNAL(highlighted(int)), this, SLOT(Activate_2nd_Box(int)));
//connect(doublebox, SIGNAL(currentIndexChanged(int)), this, SLOT(Activate_2nd_Box(int)));
}
myComboBox::~myComboBox()
{
delete box;
delete label;
}
void myComboBox::Activate_2nd_Box(int index)
{
if(index == 5)
{
qDebug() << "index : "<< index << " highlighted";
QStringList data;
data << "Sunday" << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday";
QComboBox *box2 = new QComboBox(this);
box2->addItems( data );
box2->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks