kapoorsudhish
22nd October 2009, 12:21
Hi,
I am new to Qt Environment, i am using a QTabWidget where i am adding eight tabs to it in a for loop. the elements present on each page of the tab are same.
I am not able to get the control of widgets present on the 1st tab, can someone please help me on how can i get the control back on the tab one.
Pasting the code snippet.
tabWidget = new QTabWidget(parent);
tabWidget->setGeometry(0,15,650,400);
tabWidget->setStyleSheet("*{background-color:green;}");
for(int i=0; i<8;i++){
QString name(QString::number(1));
tabWidget->addTab(myfunction(),tr("Profile").append(name));
}
connect(Modelcombo,SIGNAL(currentIndexChanged(int) ),this,SLOT(stCurrentIndex(int)));
connect(colorModecombo,SIGNAL(currentIndexChanged( int)),this,SLOT(stCurrentIndex(int)));
}
/*The function is */
QWidget* Widget::myfunction(){
page = new QWidget();
page->setGeometry(0,25,650,500);
QLabel *Modelab = new QLabel(tr("Modle"),page);
Modelab->setGeometry(0,60,120,20);
Modelcombo = new QComboBox(page);
ModelcombosetGeometry(200,60,100,20);
Modelcombo->setFocusPolicy(Qt::NoFocus);
Modelcombo->addItem(tr("Normal"));
Modelcombo->addItem(tr("Bad"));
Modelcombo->addItem(tr("Good"));
QLabel *colorModelab = new QLabel(tr("Color"),page);
colorModelab->setGeometry(0,100,80,20);
colorModecombo = new QComboBox(page);
colorModecombo->setGeometry(200,100,100,20);
colorModecombo->setFocusPolicy(Qt::NoFocus);
colorModecombo->addItem(tr("Red"));
colorModecombo->addItem(tr("Blue"));
colorModecombo->addItem(tr("Green"));
return page;
}
/*the Slot is*/
void Widget::stCurrentIndex(int val){
qDebug()<< "Tab value is" << tabWidget->currentIndex();
qDebug()<< "Modle mode is" << Modelcombo->currentText();
qDebug()<< "Color is" << colorModecombo->currentText();
}
As the content in each tab is the same when i try to connect to signal of combobox in tab 1, the signal is not emitted, but the signal is emitted for the last tab created. Please let me know hw to proceed from here as i want to extract the values of combobox of wach tab.
I am new to Qt Environment, i am using a QTabWidget where i am adding eight tabs to it in a for loop. the elements present on each page of the tab are same.
I am not able to get the control of widgets present on the 1st tab, can someone please help me on how can i get the control back on the tab one.
Pasting the code snippet.
tabWidget = new QTabWidget(parent);
tabWidget->setGeometry(0,15,650,400);
tabWidget->setStyleSheet("*{background-color:green;}");
for(int i=0; i<8;i++){
QString name(QString::number(1));
tabWidget->addTab(myfunction(),tr("Profile").append(name));
}
connect(Modelcombo,SIGNAL(currentIndexChanged(int) ),this,SLOT(stCurrentIndex(int)));
connect(colorModecombo,SIGNAL(currentIndexChanged( int)),this,SLOT(stCurrentIndex(int)));
}
/*The function is */
QWidget* Widget::myfunction(){
page = new QWidget();
page->setGeometry(0,25,650,500);
QLabel *Modelab = new QLabel(tr("Modle"),page);
Modelab->setGeometry(0,60,120,20);
Modelcombo = new QComboBox(page);
ModelcombosetGeometry(200,60,100,20);
Modelcombo->setFocusPolicy(Qt::NoFocus);
Modelcombo->addItem(tr("Normal"));
Modelcombo->addItem(tr("Bad"));
Modelcombo->addItem(tr("Good"));
QLabel *colorModelab = new QLabel(tr("Color"),page);
colorModelab->setGeometry(0,100,80,20);
colorModecombo = new QComboBox(page);
colorModecombo->setGeometry(200,100,100,20);
colorModecombo->setFocusPolicy(Qt::NoFocus);
colorModecombo->addItem(tr("Red"));
colorModecombo->addItem(tr("Blue"));
colorModecombo->addItem(tr("Green"));
return page;
}
/*the Slot is*/
void Widget::stCurrentIndex(int val){
qDebug()<< "Tab value is" << tabWidget->currentIndex();
qDebug()<< "Modle mode is" << Modelcombo->currentText();
qDebug()<< "Color is" << colorModecombo->currentText();
}
As the content in each tab is the same when i try to connect to signal of combobox in tab 1, the signal is not emitted, but the signal is emitted for the last tab created. Please let me know hw to proceed from here as i want to extract the values of combobox of wach tab.