PDA

View Full Version : customized Combobox



SSqt5.2
28th October 2014, 11:26
Hi,
i am interested to create a combo-box which should appear as shown below.
10707

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.




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();
}
}

anda_skoa
28th October 2014, 11:50
The second widget in your image does not look like a combobox, but like a popup menu. See QMenu.

Cheers,
_

SSqt5.2
30th October 2014, 06:41
Thanks for reply,

I have managed to create the required scenario.
I have created the first combobox having values ONE_1 till SiX_6, then i have cerated a signal and slot

connect(this, SIGNAL(highlighted(int)), this, SLOT(Activate_2nd_Box(int)));

slot is defined as
void myComboBox::Activate_2nd_Box(int index)
{
if(index == 5)
{
qDebug() << "index : "<< index << " highlighted";
QStringList data;
data << "Sunday" << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday";
QListWidget *list_days = new QListWidget ( parentWidget() );
list_days->addItems ( data );
list_days->move(300,100);
list_days->resize(150,150);
QFont font2 = list_days->font();
font2.setPointSize(15);
list_days->setFont(font2);
list_days->show();
}
}


This makes the QList to appear even if i remove mouse-focus from index-5.
i want to show the QList only when mouse focuses on index 5. else it should not appear.
How can i code this?

Also when i am showing the above combo-box and QList , other screen should be dark or disabled how to code this?

anda_skoa
30th October 2014, 07:20
First: please use code tags when posting code
Second: if you want to hide the window when the index is not 5, call its hide() methid
Third: try window flag Qt::Popup

Cheers,
_