Results 1 to 4 of 4

Thread: set QLayout to QDockWidget

  1. #1
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default set QLayout to QDockWidget

    I'm going to create a modified class of QDockWidget (lets call the class QAlexDockWidget) and place several objects of that class on my MainWindow during my App is running. The design of that class should be defined by layouts.

    This is a function of the class QAlexDockWidget
    Qt Code:
    1. void QAlexDockWidget::setLayout_List()
    2. {
    3. QVBoxLayout *vLayout = new QVBoxLayout;
    4. QHBoxLayout *hLayout = new QHBoxLayout;
    5. QListView *listView = new QListView;
    6. QPushButton *btnNew = new QPushButton;
    7. QPushButton *btnDel = new QPushButton;
    8. QPushButton *btnEdit = new QPushButton;
    9. hLayout->addWidget(btnNew);
    10. hLayout->addWidget(btnDel);
    11. hLayout->addWidget(btnEdit);
    12. vLayout->addWidget(listView);
    13. vLayout->addLayout(hLayout);
    14. this->setLayout(vLayout);
    15. }
    To copy to clipboard, switch view to plain text mode 

    My problem is, when i run the application the AlexDockWidget is still empty and I get the debugger message

    QWidget::setLayout: Attempting to set QLayout "" on QAlexDockWidget "Titelleiste", which already has a layout
    Why is there an existig layout and how could I place my own layout instead of this default layout?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: set QLayout to QDockWidget

    You apply this layout to your own QWidget and then use QDockWidget::setWidget() to make that the widget that QDockWidget is wrapping.

  3. The following 2 users say thank you to ChrisW67 for this useful post:

    frankiefrank (10th March 2011), WilliamSpiderWeb (4th March 2011)

  4. #3
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: set QLayout to QDockWidget

    If I understand you the right way, I should do something like that.

    Qt Code:
    1. void QAlexDockWidget::setLayout_List()
    2. {
    3. QWidget *widLayout = new QWidget;
    4. QVBoxLayout *vLayout = new QVBoxLayout;
    5. QHBoxLayout *hLayout = new QHBoxLayout;
    6. QListView *listView = new QListView;
    7. QPushButton *btnNew = new QPushButton;
    8. QPushButton *btnDel = new QPushButton;
    9. QPushButton *btnEdit = new QPushButton;
    10. hLayout->addWidget(btnNew);
    11. hLayout->addWidget(btnDel);
    12. hLayout->addWidget(btnEdit);
    13. vLayout->addWidget(listView);
    14. vLayout->addLayout(hLayout);
    15. widLayout->setLayout(vLayout);
    16. this->setWidget(widLayout);
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    Isn't it?

  5. The following user says thank you to WilliamSpiderWeb for this useful post:

    frankiefrank (10th March 2011)

  6. #4
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: set QLayout to QDockWidget

    Yeah, that works.

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2010, 21:46
  2. Resize QLayout w/ Mouse...or, a QWidget similar to QDockWidget
    By kiss-o-matic in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2009, 10:05
  3. QLayout
    By sudeepdua in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 10:46
  4. A bug of QLayout
    By cocalele in forum Qt Programming
    Replies: 6
    Last Post: 26th April 2006, 06:10
  5. qlayout and setGeometry
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2006, 12:56

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.