How to access Widgets created in Tab View
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.
Code:
tabWidget->setGeometry(0,15,650,400);
tabWidget->setStyleSheet("*{background-color:green;}");
for(int i=0; i<8;i++){
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 */
page->setGeometry(0,25,650,500);
Modelab->setGeometry(0,60,120,20);
ModelcombosetGeometry(200,60,100,20);
Modelcombo->setFocusPolicy(Qt::NoFocus);
Modelcombo->addItem(tr("Normal"));
Modelcombo->addItem(tr("Bad"));
Modelcombo->addItem(tr("Good"));
colorModelab->setGeometry(0,100,80,20);
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.
Re: How to access Widgets created in Tab View
What do you mean by "control"?
Re: How to access Widgets created in Tab View
By "control" i mean, i am not able to get the value changed in the combobox of tab 0, if i try
connect(Modelcombo,SIGNAL(currentIndexChanged(int) ),this,SLOT(stCurrentIndex(int)));
connect(colorModecombo,SIGNAL(currentIndexChanged( int)),this,SLOT(stCurrentIndex(int)));
the value shown in the slot is the value of combobox of tab7 and not tab 0, by some way i want the value of the combobox present in each tab individually.
Is the way page created to add to the tab is correct, as all the tabs are having same widgets.
Re: How to access Widgets created in Tab View
This code certainly helped as what i was doing initially was incorrect
Code:
for(int i=0; i<8;i++)
{
QLabel *recordingModelab
[i
] = new QLabel(tr
("Recording Mode"),page
[i
]);
recordingModelab[i]->setGeometry(0,60,120,20);
recordingModecombo
[i
] = new QComboBox(page
[i
]);
recordingModecombo[i]->setGeometry(200,60,100,20);
recordingModecombo[i]->setFocusPolicy(Qt::NoFocus);
recordingModecombo[i]->addItem(tr("Normal"));
recordingModecombo[i]->addItem(tr("Bad"));
recordingModecombo[i]->addItem(tr("Good"));
QLabel *resolutionModelab
[i
] = new QLabel(tr
("Resolution"),page
[i
]);
resolutionModelab[i]->setGeometry(0,100,80,20);
resolutionModecombo
[i
] = new QComboBox(page
[i
]);
resolutionModecombo[i]->setGeometry(200,100,100,20);
resolutionModecombo[i]->setFocusPolicy(Qt::NoFocus);
resolutionModecombo[i]->addItem(tr("CIF"));
resolutionModecombo[i]->addItem(tr("D1"));
resolutionModecombo[i]->addItem(tr("QCIF"));
qualitylab[i]->setGeometry(0,140,80,20);
qualitycombo[i]->setGeometry(200,140,100,20);
qualitycombo[i]->setFocusPolicy(Qt::NoFocus);
qualitycombo[i]->addItem(tr("50 kbps"));
qualitycombo[i]->addItem(tr("120 kbps"));
qualitycombo[i]->addItem(tr("150 kbps"));
qualitycombo[i]->addItem(tr("200 kbps"));
QLabel *frameratelab
[i
] = new QLabel(tr
("Frame Rate"),page
[i
]);
frameratelab[i]->setGeometry(0,180,80,20);
frameratecombo[i]->setGeometry(200,180,100,20);
frameratecombo[i]->setFocusPolicy(Qt::NoFocus);
frameratecombo[i]->addItem(tr("15 fps"));
frameratecombo[i]->addItem(tr("25 fps"));
frameratecombo[i]->addItem(tr("30 fps"));
tabWidget->addTab(page[i],tr("Profile").append(name));
}
If the same can be done in a better way, please share
Re: How to access Widgets created in Tab View
If all the tabs contain the same widgets (and they certainly seem to from your code), then you could create another ui file with your widgets, and then either:
- subclass QWidget using Designers promotion feature and then use the same object for each tab (designer way)
- create 8 copies of the object using 'new' and manually add the tabs using tabWidget->addTab
Either way needs a lot less code than what you have.
Re: How to access Widgets created in Tab View
I tried creating 8 copies of the page object, but when i tried to access the values from the comboboxes on tab0, it gave the values of combobox 7 so i tried in this way.