I am developing an application with tabviews. I want that tabView to change the widget depending on the ComboBox choice. ex: if the first index chosen I want tabView1 to appear if the second index chosen I want tabView2 to appear I tired few methods, if(str == "a") layout->tabview1; else layout->tabView2. I also tried the connect(combobox,SIGNAL(currentTextChanged()),this,SIGNAL(swithcall())) one of the main problems I can't do much instructions in swticahll function because in that case I will have to identify the tabviews as global variables which is not the best choice. Any recommendations?
CodePudding user response:
You can use lambdas inside a connect line, ex:
connect(combobox,&QComboBox::currentIndexChanged,this,[tabView](int index) mutable{
// change tabView as wanted
});
If you want to change by text and index (not just index like here), you can use (inside the lambda):
QString currText = combobox->currentText();
CodePudding user response:
You can just connect QComboBox
's signal currentIndexChanged
to QTabWidget
's setCurrentIndex
slot like connect(combobox, &QComboBox::cutrentIndexChanged, tabview, &QTabWidget::setCurrentIndex)
, and add widgets to your tabview
in the required order that corresponds to items order in your combobox
.