QTabWidget - Add Tabs dynamically
HI...I have a problem with the dynamically add of tabs to a tabwidget.
I create a GUI with a TabWidget...now, by code, when I add a tab wich has inside a widget created by mine Alarm1 (it has some qlabel and qbuttons inside), the tab was created and added but It don't display anything about the widget Alarm1. Strange because the same code in the constructor works fine like I want. Why?
This is part of the code:
Code:
//Add Alarm to Alarms List
tab
= new QWidget( twAlarms,
"tab" );
Alarm1 * alm = new Alarm1(alarm,tab);
tabLayout->addWidget(alm);
twAlarms
->insertTab
( tab,
QString::fromLatin1("Alarm 1") );
connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmSent()));
In the constructor instead the code is:
Code:
twAlarms->removePage(tab);
tab->close();
for (int i=0; i<3; i++) {
tab
= new QWidget( twAlarms,
"tab" );
Alarm1 * alm = new Alarm1(alarm, tab);
tabLayout->addWidget(alm);
twAlarms
->insertTab
( tab,
QString::fromLatin1("Alarm"+QString::number(i
)) );
connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmSent()));
}
Re: QTabWidget - Add Tabs dynamically
A widget is hidden by default. Tabs created in constructor are shown together with their parent. You must make tabs added dynamically at runtime visible by yourself. Try adding:
Re: QTabWidget - Add Tabs dynamically
ok I put the line tab->show(); after the connect and so work fine.....now I have a problem with the layout.....the alarm1 widget is printed outside the tab too and not all in the tab, why?
Re: QTabWidget - Add Tabs dynamically
Hard to say, it seems to be a custom widget we know nothing about. Since it's properly added to a layout (is it?), it presumably does something that breaks the layout.
Re: QTabWidget - Add Tabs dynamically
mhmmm...it's strange because I have the same problem if I add in the tab a simble button instead the widget alarm1 :eek:
Re: QTabWidget - Add Tabs dynamically
Quote:
Originally Posted by
fruzzo
mhmmm...it's strange because I have the same problem if I add in the tab a simble button instead the widget alarm1 :eek:
Take a look of undo shape example of QtDemo. It's work fine.
Re: QTabWidget - Add Tabs dynamically
Quote:
Originally Posted by
ashukla
Take a look of undo shape example of QtDemo. It's work fine.
I don't find it...link?
Re: QTabWidget - Add Tabs dynamically
You can see it in your system folder undo folder.
Re: QTabWidget - Add Tabs dynamically
And just to comment: I've read in the docs that widget. which will be used, must be previously created WITHOUT parent.
Re: QTabWidget - Add Tabs dynamically
ok I've resolved the problem...it was releated to tab->show() that doesn't work well.
I use instead twAlarms->showPage(...) and now the layout is fine. :p
Re: QTabWidget - Add Tabs dynamically
another problem.... in my QTabWidget I have several tabs that may be of two kinds: tab with inside Alarm1 Widget and tab with inside Alarm2 Widget....Alarm1 and Alarm2 have both a QLabel like an unique identifier of the alarm type.
Now I want to search in the whole QTabWidget which tab containe the Alarm with a particular "identifier"....any idea how to do this?
Re: QTabWidget - Add Tabs dynamically
Use a QHash with either your QLabel or a QString as a lookup index for your alarm widget. There are many examples of similar lookups in QtDemo.