Results 1 to 2 of 2

Thread: [SOLVED]Adding dynamically created widgets to layout error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default [SOLVED]Adding dynamically created widgets to layout error

    I'm creating an array of widgets and I'm trying to add them to the main layout but I get an error.

    Qt Code:
    1. QLabel *colorBoxes = new QLabel[numLights];
    2. for(int i = 0; i < numLights; i++)
    3. {
    4. colorBoxes[i].setText(description[i]);
    5. ui->mainLayout->addWidget(colorBoxes[i]);
    6. }
    To copy to clipboard, switch view to plain text mode 



    It says it can't convert QLabel to QWidget*. It worked before in another project, I have no idea why this is doing it now?


    apparently to make it work, I needed to add it as
    Qt Code:
    1. ui->mainLayout->addWidget(colorBoxes[i].window());
    To copy to clipboard, switch view to plain text mode 
    Last edited by bnosam; 7th April 2015 at 02:47.

Similar Threads

  1. Adding widgets to layout dynamically
    By anbu01 in forum Newbie
    Replies: 2
    Last Post: 15th May 2014, 12:41
  2. trouble when moving dynamically created custom Widgets
    By chocolateSteak in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2013, 00:38
  3. Replies: 3
    Last Post: 11th August 2011, 17:16
  4. Replies: 5
    Last Post: 18th April 2010, 23:31
  5. Adding widgets dynamically
    By miw in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2009, 10:31

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.