Results 1 to 9 of 9

Thread: DockWidget ?

  1. #1
    Join Date
    May 2006
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default DockWidget ?

    I have a widget that I cannot get to "show up" inside of my dock widget. It shows up un-docked on top of my main window. My widget is just a clock with some VCR-like buttons (play, stop,etc).
    A dock widget is created on my main window at the top like I want, but nothing is in it.

    Here is my set up for my clock:

    Qt Code:
    1. class cClockDlg : public QWidget, public Ui::cClockDlg
    2. {
    3. Q_OBJECT
    4. public:
    5. cClockDlg(QWidget * parent = 0);
    6. ...
    7. };
    To copy to clipboard, switch view to plain text mode 

    And then in my mainWindow where I try to make it a dockWidget:

    Note: I call this method in my mainWindow constructor after I call setupUi(this).

    Qt Code:
    1. void cMainWindow::setupClockWidget()
    2. {
    3. QDockWidget * clockDockWidget = new QDockWidget(tr("Simulation Clock"), this);
    4. clockDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    5. mClockDlg = new cClockDlg(clockDockWidget);
    6. clockDockWidget->setWidget(mClockDlg);
    7. addDockWidget(Qt::TopDockWidgetArea, clockDockWidget);
    8. } // cMainWindow::setupClockWidget
    To copy to clipboard, switch view to plain text mode 

    Any ideas on what I'm doing wrong? TIA.

  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: DockWidget ?

    Is "cClockDlg", by any chance, designed as a dialog project in the Qt Designer?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Location
    The Hague, The Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DockWidget ?

    I understand you call setupUi() BEFORE you construct the cClockDlg. You`re supposed to call setupUi() inside the constructor of cClockDg. A look inside ui_cclockdlg at the setupUi method will explain why you don`t see your widgets inside your dialog.

    zeeeend

  4. #4
    Join Date
    May 2006
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DockWidget ?

    Yes, cClockDlg is a dialog created in Designer. And in cClockDlg constructor I call its setupUi(this).

  5. #5
    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: DockWidget ?

    My first thought was that it was all about QDialog. QDialog is a special widget that behaves differently than all other widgets (it's always a top level widget, regardless of the parent). Anyway, this seems not to be the case since cClockDlg is just a plain QWidget (and I don't suspect you would be setting the window type as Qt::Dialog). It's just the naming that got me confused.. ;)

    All I can come up with is a parenting issue. How does the constructor of cClockDlg look like? Are you calling the base class constructor to pass the parent?

    Qt Code:
    1. cClockDlg::cClockDlg(QWidget * parent) : QWidget(parent) // <-- forgot this?
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #6
    Join Date
    May 2006
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DockWidget ?

    Yeah, I should have changed the name, but it was originally designed to be a dialog but we changed it to a QWidget. Sorry for the confusion.

    Anyway, this is cClockDlg constructor. Nothing fancy.

    Qt Code:
    1. cClockDlg::cClockDlg(QWidget * parent) :
    2. QWidget(parent)
    3. {
    4. setupUi(this);
    5. } // cClockDlg::cClockDlg
    To copy to clipboard, switch view to plain text mode 

  7. #7
    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: DockWidget ?

    Try reproducing it with a minimal example and/or isolating the problem in the actual project by commenting out everything but essential to reproduce the problem.. It still sounds like a parenting issue, but at least I can't see anything wrong with the snippets you have provided.

    You could use QObject::dumpObjectTree() to examine the hierarchy of the objects.
    J-P Nurmi

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DockWidget ?

    From your earlier post...
    Note: I call this method in my mainWindow constructor after I call setupUi(this).
    how many times are u calling setupUI() ?? u need to call it once in cClockDlg constructor...
    are u calling it in cMainWindow constructor too ??

  9. #9
    Join Date
    May 2006
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DockWidget ?

    jpn,
    I finally got to your suggestion. And called dumpObject tree this way:
    Qt Code:
    1. void cMainWindow::setupClockWidget()
    2. {
    3. QDockWidget * clockDockWidget = new QDockWidget(tr("Simulation Clock"), this);
    4. clockDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    5. mClockDlg = new cClockDlg(clockDockWidget);
    6. clockDockWidget->setWidget(mClockDlg);
    7. addDockWidget(Qt::TopDockWidgetArea, clockDockWidget);
    8. clockDockWidget->dumpObjectTree();
    9. } // cMainWindow::setupClockWidget
    To copy to clipboard, switch view to plain text mode 

    And got this result:
    [HTML]
    QDockWidget::
    QGridLayout::
    QVBoxLayout::
    QWidgetResizeHandler::
    QAction::
    QDockWidgetTitleButton::
    QDockWidgetTitleButton::
    cClockDlg::cClockDlg
    QWidget::layoutWidget
    QHBoxLayout::hboxLayout
    QPushButton::mToStart
    QPushButton::mReverseFast
    QPushButton::mReverse
    QPushButton::mPause
    QPushButton::mForward
    QPushButton::mForwardFast
    QPushButton::mToEnd
    QWidget::layoutWidget1
    QHBoxLayout::hboxLayout1
    QLabel::mTimeLabel
    QTimeEdit::mTimeEdit
    QLineEdit::qt_spinbox_lineedit
    QAction::
    QAction::
    QAction::
    QAction::
    QAction::
    QAction::
    QAction::
    QValidator::qt_spinboxvalidator
    QScrollBar::mTimeScrollBar
    [/HTML]

    I think you're right in that it's a parenting issue, because I don't see any reference to the MainWindow in this heirarchy. I thought that "this" in this call:
    Qt Code:
    1. QDockWidget * clockDockWidget = new QDockWidget(tr("Simulation Clock"), this);
    To copy to clipboard, switch view to plain text mode 
    set up the reference to the main window.

Similar Threads

  1. Redesigning a DockWidget
    By Dr. Norbert Prang in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2011, 11:55

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.