Results 1 to 3 of 3

Thread: Reorganize elements in a QGridLayout

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Reorganize elements in a QGridLayout

    Hi,

    I have a QGridLayout in a Widget. This layout is divided into four parts by placing four widgets in it.

    I want to be able to remove the four internal widgets and the just put one of them in the layout (which will occupy the whole space).

    I am currently using the following code to remove the elements in the layout (without destroying them because I want to reuse them later) :

    Qt Code:
    1. QLayoutItem *child;
    2. while((child = this->gridLayout->takeAt(0)) != 0);
    To copy to clipboard, switch view to plain text mode 

    And then I add the new widget in the layout.

    My problem is that the old items are still visible and the new one is just displayed on them...I don't understand why. The old widgets are displayed but they don't follow the layout rules (like they are not in it, they are just still "present" in the display).

    Any leads ?

    Thanks

    PS 1 : The widget are actually QwtPlot and here is what I see on the scale for example : scale.jpg
    PS 2 : Also, the same thing is observed when I delete the layout and create a new one. Some how, the old one is still visible.
    PS 3 : The problem can be seen with this code

    Qt Code:
    1. QWidget *w = new QWidget();
    2. w->setLayout(new QGridLayout());
    3. static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 0, 0);
    4. static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 0, 1);
    5. static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 1, 0);
    6. static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 1, 1);
    7. delete w->layout();
    8. w->setLayout(new QGridLayout());
    9. static_cast<QGridLayout*>(w->layout())->addWidget(new QLabel(QString("hey")), 0, 0);
    10. w->show();
    To copy to clipboard, switch view to plain text mode 

    Running that displays the label in the new label (in place) but there is still one old button in the background (it is unclickage, it is just drawn)...
    Last edited by moijhd; 26th March 2013 at 09:01.

Similar Threads

  1. Print QML elements
    By merajc in forum Qt Quick
    Replies: 0
    Last Post: 15th August 2012, 23:04
  2. Ready to use QML elements
    By .:saeed:. in forum Qt Quick
    Replies: 0
    Last Post: 22nd February 2011, 16:25
  3. Ui Elements (QLineEdit) + QML
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2010, 16:04
  4. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 13:01
  5. Elements out of Range!!
    By Kapil in forum Newbie
    Replies: 9
    Last Post: 3rd April 2006, 10:28

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.