Results 1 to 6 of 6

Thread: QWizard creating objects dynamically

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    48
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QWizard creating objects dynamically

    Quote Originally Posted by Lykurg View Post
    Hi,



    Lykurg
    Hmm do you have a snippet of code / example for this. I just can't picture what you're telling me in code.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QWizard creating objects dynamically

    Ok, i try.
    You have 2 pages in an QWizard. Already full designed (in designer) and on the second page is an empty layout for the "something" which number gets defined on page1.

    Qt Code:
    1. XYZ::initializePage(int id)
    2. {
    3. if (id==1) // page2
    4. {
    5. QWidget *w = page(id);
    6. // finding the layout or when hand coded use the pointer
    7. // to the layout direct
    8. QLayout *layout = w->findChild<QLayout *>("nameSetInDesigner");
    9. // and now populate the "something": cnt is the number;
    10. if (cnt < layout->findChild<Something *>())
    11. {
    12. //remove
    13. Something *smt = layout->findChild<Something *>().last();
    14. layout->removeWidget(smt);
    15. delete smt;
    16. }
    17. else
    18. {
    19. //add
    20. layout->addWidget(new Something(layout));
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Not proofed!

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

    afflictedd2 (24th March 2009)

  4. #3
    Join Date
    Jul 2008
    Posts
    48
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QWizard creating objects dynamically

    Hi everyone,

    This time I'm facing a new problem :\. When I register a field, in the initializePage() I cannot go back and forth again in the wizard because it will attempt to register that field again. Is it possible to unregister a field when I go back?

    Qt Code:
    1. void ObjectsPage::initializePage()
    2. {
    3. layout = new QGridLayout;
    4. QSpinBox* sbVel = NULL;
    5. QLabel* lblVel = NULL;
    6.  
    7. QString numLayers = field("numObjs").toString();
    8. int num = numLayers.toInt();
    9.  
    10. for (int i = 0; i < num; ++i) {
    11. sbVel = new QSpinBox();
    12. sbVel->setMinimum(500);
    13. sbVel->setMaximum(20000);
    14. sbVel->setSingleStep(500);
    15. sbVel->setValue((i+1)*500);
    16.  
    17. lblVel = new QLabel;
    18. lblVel->setText("Capa " + QString::number(i+1));
    19. sbObjs.push_back(sbVel);
    20. lblObjs.push_back(lblVel);
    21. layout->addWidget(lblVel, i, 0);
    22. layout->addWidget(sbVel, i, 1);
    23. registerField("sbVel" + QString::number(i), sbObjs[i]);
    24. }
    25.  
    26. setLayout(layout);
    27. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 8
    Last Post: 20th April 2007, 01:37
  2. creating objects in a for()
    By phil_ in forum Newbie
    Replies: 3
    Last Post: 21st January 2006, 14:16

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.