Results 1 to 3 of 3

Thread: Array of widgets

  1. #1
    Join Date
    Jun 2009
    Posts
    44
    Qt products
    Qt4
    Platforms
    Windows

    Default Array of widgets

    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)?

  2. #2
    Join Date
    Feb 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Array of widgets

    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:

    Qt Code:
    1. QMap<int, QWidget *> map;
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. for(int i = 0; i < 7; i++)
    2. {
    3. map[i] = new QPushButton(QString("Button %1").arg(i), this);
    4. map[i]->setGeometry(0, i * 50, 50, 50);
    5. map[i] = new QLabel(QString("Label %1").arg(i), this);
    6. map[i]->setGeometry(100, i * 50, 50, 50);
    7. }
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Jun 2009
    Posts
    44
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Array of widgets

    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

Similar Threads

  1. How To Create Array of Widgets in Qt4?
    By redhat in forum Newbie
    Replies: 4
    Last Post: 27th April 2009, 10:37
  2. Create an array of Widgets
    By gt.beta2 in forum Qt Tools
    Replies: 4
    Last Post: 25th February 2009, 19:44
  3. Mac OS X Top-Level Transparent Widgets
    By tinsuke in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 16:01
  4. Upper limit on number of widgets?
    By jdiewald in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2008, 23:00
  5. Replies: 2
    Last Post: 16th May 2008, 14:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.