Results 1 to 5 of 5

Thread: Create an array of Widgets

  1. #1
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Create an array of Widgets

    Hello
    Is it possible to create an array of Widgets inside the ui file?
    Something like 3 QPushButtons that could then be used as :
    array[0]->setText("blá");

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Create an array of Widgets

    No, but you can create such an array in the widget subclass you implement to use the ui file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    gt.beta2 (25th February 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: Create an array of Widgets

    And how can i put them in the interface along with the other widgets already created using Designer?!

  5. #4
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: Create an array of Widgets

    Here is a possibility:
    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3.  
    4. Dialog::Dialog(QWidget *parent)
    5. : QDialog(parent), ui(new Ui::DialogClass)
    6. {
    7. ui->setupUi(this);
    8. QLineEdit *array[3];
    9. array[0] = ui->l1;
    10. array[1] = ui->l2;
    11. array[2] = ui->l3;
    12. for(int i = 0; i < 3 ; i++)
    13. array[i]->setText("yess!");
    14. }
    15.  
    16. Dialog::~Dialog()
    17. {
    18. delete ui;
    19. }
    To copy to clipboard, switch view to plain text mode 

    l1, l2 and l3 are QLineEdit objects created using Designer.
    array[0], array[1] and array[2] are the "clones"

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Create an array of Widgets

    Yes, that's exactly what I meant. And they are not clones, they are just pointers to the same data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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. Using a 2d data array to create an image
    By dbrmik in forum Newbie
    Replies: 20
    Last Post: 28th October 2008, 17:22
  3. How to create Custom Slot upon widgets
    By ashukla in forum Qt Programming
    Replies: 6
    Last Post: 8th September 2007, 14:07
  4. How to create a movable border between two widgets?
    By Teuniz in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2007, 08:45
  5. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25

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.