PDA

View Full Version : DockWidget ?



allensr
17th January 2007, 18:24
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:



class cClockDlg : public QWidget, public Ui::cClockDlg
{
Q_OBJECT
public:
cClockDlg(QWidget * parent = 0);
...
};


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).



void cMainWindow::setupClockWidget()
{
QDockWidget * clockDockWidget = new QDockWidget(tr("Simulation Clock"), this);
clockDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
mClockDlg = new cClockDlg(clockDockWidget);
clockDockWidget->setWidget(mClockDlg);
addDockWidget(Qt::TopDockWidgetArea, clockDockWidget);
} // cMainWindow::setupClockWidget


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

jpn
17th January 2007, 18:35
Is "cClockDlg", by any chance, designed as a dialog project in the Qt Designer?

zeeeend
17th January 2007, 19:45
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

allensr
17th January 2007, 20:53
Yes, cClockDlg is a dialog created in Designer. And in cClockDlg constructor I call its setupUi(this).

jpn
18th January 2007, 15:48
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?



cClockDlg::cClockDlg(QWidget * parent) : QWidget(parent) // <-- forgot this?
{
...
}

allensr
18th January 2007, 17:47
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. :o

Anyway, this is cClockDlg constructor. Nothing fancy.



cClockDlg::cClockDlg(QWidget * parent) :
QWidget(parent)
{
setupUi(this);
} // cClockDlg::cClockDlg

jpn
18th January 2007, 21:52
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.

aamer4yu
19th January 2007, 04:24
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 ??

allensr
30th January 2007, 23:58
jpn,
I finally got to your suggestion. And called dumpObject tree this way:


void cMainWindow::setupClockWidget()
{
QDockWidget * clockDockWidget = new QDockWidget(tr("Simulation Clock"), this);
clockDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
mClockDlg = new cClockDlg(clockDockWidget);
clockDockWidget->setWidget(mClockDlg);
addDockWidget(Qt::TopDockWidgetArea, clockDockWidget);
clockDockWidget->dumpObjectTree();
} // cMainWindow::setupClockWidget


And got this result:


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


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:


QDockWidget * clockDockWidget = new QDockWidget(tr("Simulation Clock"), this);

set up the reference to the main window.