Results 1 to 3 of 3

Thread: Add QWidget to QDockWidget

  1. #1
    Join Date
    Dec 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question Add QWidget to QDockWidget

    Hello. I am trying to add a QPushButton dynamically.

    Qt Code:
    1. QPushButton* pushButton = new QPushButton(m_pUI->dockSelectionView);
    2. pushButton->setObjectName(QStringLiteral("pushButton"));
    3. pushButton->setGeometry(QRect(60, 140, 75, 23));
    4. m_pCogSparkzEditorClass->layout()->addWidget(pushButton);
    To copy to clipboard, switch view to plain text mode 

    This adds a button, but not to the dock widget.

    If I add a QPushButton in the designer, when I change the size of the docked widget the button moves accordingly.
    But when I try to add it in code, passing the parent in the constructor - it behaves as if I just added it to the QMainWindow and not to the dock widget.

    So my questions is: How do I add a QWidget to a QDockWidget?

    Many thanks, Jack.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add QWidget to QDockWidget

    You are adding the button to the layout of "m_pCogSparkzEditorClass", so it gets reparented to whatever that widget is.

    Cheers,
    _

  3. #3
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Add QWidget to QDockWidget

    Qt Code:
    1. void QDockWidget::setWidget(QWidget * widget)
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to Vikram.Saralaya for this useful post:

    Jack_Holmes (31st December 2015)

Similar Threads

  1. QDockWidget inside QDockWidget
    By mqt in forum Qt Programming
    Replies: 3
    Last Post: 1st July 2013, 13:57
  2. Replies: 5
    Last Post: 28th November 2011, 08:20
  3. Replies: 1
    Last Post: 7th December 2010, 22:46
  4. 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, 11:05
  5. Replies: 5
    Last Post: 16th September 2006, 15:09

Tags for this Thread

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.