Results 1 to 20 of 27

Thread: Dynamically created buttons.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically created buttons.

    hi ,
    u can use QHash too.
    i will use like this ,

    Qt Code:
    1. QHash<int,QPushButton*> btn;
    2.  
    3. int HOW_MANY_BUTTONS=200; //u can change this value dynamically as u wish;
    4. for(int j=0; j<HOW_MANY_BUTTONS; j++)
    5. {
    6. btn[j]=b;
    7. b->setGeometry(0,0,40,40);
    8. ui->verticalLayout->addWidget(b,Qt::AlignVCenter);
    9. }
    To copy to clipboard, switch view to plain text mode 

    hope it helps

    Bala

  2. The following user says thank you to BalaQT for this useful post:

    Tomasz (29th November 2010)

  3. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dynamically created buttons.

    Note also, in addition to the above, that a QLayout itself acts much like a vector: it has count(), addItem(), removeItem() and itemAt() functions that might serve just as well as using an external vector to keep track of the items managed by the layout. It isn't really possible to say whether this approach would work without knowing more about your application, but sometimes it allows you to use a single object - the layout - rather than two - the layout plus an external container.

Similar Threads

  1. Dynamically creating buttons from Xml file
    By chandru@080 in forum Newbie
    Replies: 5
    Last Post: 25th November 2010, 10:34
  2. PaintEvent() in a dynamically created and destroyed objet not working.
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 20th October 2010, 08:49
  3. Check has created with new
    By wirasto in forum Qt Programming
    Replies: 5
    Last Post: 16th March 2010, 16:02
  4. QMainWindow ignores dynamically created, floating QDockWidget
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2010, 01:06
  5. Line not being created
    By Kapil in forum Newbie
    Replies: 4
    Last Post: 30th March 2006, 06:49

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
  •  
Qt is a trademark of The Qt Company.