Results 1 to 3 of 3

Thread: change layout dynamicly

  1. #1
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question change layout dynamicly

    Hi,

    I have problem when change the layout dynamicly.
    The layout seems not be changed.

    I had a look for the example already. But in my case it doesn't work. I post my code here:

    One and the only one method in constructor:
    Qt Code:
    1. void xyzWidget::create(bsDoubleMode mode, double minimum, double maximum, bool periodic, bool horizontal)
    2. {
    3. setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
    4. if(horizontal)
    5. setLayout(new QHBoxLayout(this));
    6. else
    7. setLayout(new QVBoxLayout(this));
    8.  
    9. layout()->setMargin(0);
    10.  
    11. w_xyzGroupBox = new QGroupBox(this);
    12. w_xyzGroupBox->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
    13. if(horizontal)
    14. w_xyzGroupBox->setLayout(new QHBoxLayout(w_xyzGroupBox));
    15. else
    16. w_xyzGroupBox->setLayout(new QVBoxLayout(w_xyzGroupBox));
    17. w_xyzGroupBox->hide();
    18.  
    19. w_xValue = new bsDoubleWidget(this, mode, minimum, maximum, periodic);
    20. w_xValue->setLabel(tr("X :"));
    21. w_xValue->setLabelColor(QColor(200, 0, 0));
    22. connect(w_xValue, SIGNAL(valueChanged(double)), this, SLOT(xyzChanged(double)));
    23. connect(w_xValue, SIGNAL(editingBegin()), this, SIGNAL(xyzEditingBegin()));
    24. connect(w_xValue, SIGNAL(editingFinished()), this, SIGNAL(xyzEditingFinished()));
    25. layout()->addWidget(w_xValue);
    26.  
    27. w_yValue = new bsDoubleWidget(this, mode, minimum, maximum, periodic);
    28. w_yValue->setLabel(tr("Y :"));
    29. w_yValue->setLabelColor(QColor(0, 200, 0));
    30. connect(w_yValue, SIGNAL(valueChanged(double)), this, SLOT(xyzChanged(double)));
    31. connect(w_yValue, SIGNAL(editingBegin()), this, SIGNAL(xyzEditingBegin()));
    32. connect(w_yValue, SIGNAL(editingFinished()), this, SIGNAL(xyzEditingFinished()));
    33. layout()->addWidget(w_yValue);
    34.  
    35. w_zValue = new bsDoubleWidget(this, mode, minimum, maximum, periodic);
    36. w_zValue->setLabel(tr("Z :"));
    37. w_zValue->setLabelColor(QColor(0, 0, 200));
    38. connect(w_zValue, SIGNAL(valueChanged(double)), this, SLOT(xyzChanged(double)));
    39. connect(w_zValue, SIGNAL(editingBegin()), this, SIGNAL(xyzEditingBegin()));
    40. connect(w_zValue, SIGNAL(editingFinished()), this, SIGNAL(xyzEditingFinished()));
    41. layout()->addWidget(w_zValue);
    42. }
    To copy to clipboard, switch view to plain text mode 

    After I push a button, it is supposed to change the layout by calling this method:
    Qt Code:
    1. void xyzWidget::setLayoutVertical()
    2. {
    3. layout()->removeWidget(w_xValue);
    4. layout()->removeWidget(w_yValue);
    5. layout()->removeWidget(w_zValue);
    6.  
    7. setLayout(new QVBoxLayout());
    8. w_xyzGroupBox->setLayout(new QVBoxLayout(w_xyzGroupBox));
    9.  
    10. layout()->addWidget(w_xValue);
    11. layout()->addWidget(w_yValue);
    12. layout()->addWidget(w_zValue);
    13. }
    To copy to clipboard, switch view to plain text mode 

    (The groupbox will not be used any way)

    Anyone can help?

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: change layout dynamicly


  3. #3
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: change layout dynamicly

    Quote Originally Posted by fatjuicymole View Post
    I searched a little bit here. QStackedWidget was mentioned in several threads.
    But since I don't switch back and force between two widgets, I don't see the necessarity to use QStackedWidget. You will probably ask me why not change the value during initialization. I just need this switch one time.

Similar Threads

  1. Dynamically change the layout
    By pippo42 in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2009, 13:01
  2. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  3. Hide widget, but not change layout
    By dimaz in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 14:32
  4. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  5. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 07: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.