PDA

View Full Version : Array of widgets



maider
20th November 2009, 11:34
Hey,

I have a doubt! I have done a map of widgets like this:

int main( int argc, char **argv )
{
QApplication app( argc, argv );


QMap<int, MyWidget *> map;

for( int i=1; i<10; i++ ){
map[i]=new MyWidget( QObject::tr( "Window #%1" ).arg( i ) );
}

In that way i 'm not able to add the different widgets that my application has to have.
But could i add to this map the my different widgets (different .ui)?

milot
20th November 2009, 11:49
As long as I've understood your problem, you want different widget types to be added to the QMap.

Every Qt widget must be derived from QWidget, so you can create a map of QWidget pointers like this:



QMap<int, QWidget *> map;


And then add different widgets, as per our example, I've added two different widgets QPushButton and QLabel



for(int i = 0; i < 7; i++)
{
map[i] = new QPushButton(QString("Button %1").arg(i), this);
map[i]->setGeometry(0, i * 50, 50, 50);
map[i] = new QLabel(QString("Label %1").arg(i), this);
map[i]->setGeometry(100, i * 50, 50, 50);
}


the setGeometry() method is used in this example just for display/cosmetic reasons.

maider
20th November 2009, 13:13
No I don't want that!

I mean, i have created three different widgets: "first.ui","second.ui","third.ui" .
Each widget is going to have his buttons or whatever you want.

No In the project's maiN,I want to insert "first.ui","second.ui","third.ui" into a map.

Could I?

thanks