Results 1 to 5 of 5

Thread: setLayout to QDockWidget

  1. #1
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default setLayout to QDockWidget

    hi all,

    i am new to QT programming, i want to create a Dockwidget and it contain some label and text box layout, for that i create a QDockwidget object and i create QGridLayout object and addWidget as label and text box.

    while setting the layout to dockwidget it not showing the layout.
    here my code:

    Qt Code:
    1. dwidget = new QDockWidget(tr("&Name"), this);
    2. dwidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    3. dwidget->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::AllDockWidgetFeatures);
    4. dwidget->setObjectName("NEW Widget");
    5. dwidget->setWindowTitle("NewDock");
    6.  
    7. label1 = new QLabel("Name: ");
    8. txtEdit = new QLineEdit;
    9.  
    10. mainLayout = new QGridLayout();
    11. mainLayout->addWidget(label1, 0, 0);
    12. mainLayout->addWidget(txtEdit, 0, 1);
    13.  
    14. dwidget->setLayout(mainLayout);
    15.  
    16. addDockWidget(Qt::RightDockWidgetArea, dwidget);
    To copy to clipboard, switch view to plain text mode 
    it complies success but while running the program its not showing any layout on dockwidget.

    is there any solution for this?

    Regards.
    hemraj
    Last edited by jpn; 21st April 2009 at 10:59. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setLayout to QDockWidget

    You cannot install a layout on QDockWidget. You must install the layout on another widget and call QDockWidget::setWidget().
    J-P Nurmi

  3. #3
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setLayout to QDockWidget

    Hi jpn,

    i created another widget and setlayout to that widget, using the dockwidget object i set widget.
    but still it not visible.
    here my code:

    Qt Code:
    1. QWidget newWidget(this);
    2. newWidget.setLayout(mainLayout);
    3.  
    4. dwidget->setWidget(&newWidget);
    5. dwidget->show();
    6. addDockWidget(Qt::RightDockWidgetArea, dwidget);
    To copy to clipboard, switch view to plain text mode 
    Regards,
    hemraj
    Last edited by jpn; 21st April 2009 at 11:21. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setLayout to QDockWidget

    If you create the widget on the stack, it will go out of scope according to normal C++ rules.

    PS. Please start using code-tags. I already sent you instructions. Thank you.
    J-P Nurmi

  5. The following 2 users say thank you to jpn for this useful post:

    hemrajn (21st April 2009), keshav2010 (30th April 2018)

  6. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setLayout to QDockWidget

    and you will get nothing
    try this
    Qt Code:
    1. QWidget *newWidget = new QWidget(this);
    2. newWidget->setLayout(mainLayout);
    3.  
    4. dwidget->setWidget(newWidget);
    5. dwidget->show();
    6. addDockWidget(Qt::RightDockWidgetArea, dwidget);
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. The following user says thank you to spirit for this useful post:

    hemrajn (21st April 2009)

Similar Threads

  1. QDockWidget magically disapear
    By 1111 in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 11:44
  2. widget not resized within QDockWidget
    By pospiech in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2008, 18:19
  3. QDockWidget closing detection
    By danielperaza in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2008, 15:28
  4. contextmenu in QDockWidget title
    By klipko in forum Newbie
    Replies: 4
    Last Post: 7th March 2008, 22:32
  5. Replies: 8
    Last Post: 4th February 2007, 00:42

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.