QDockWidget will not go from Floating back to the docked state, why?
-
This is my widget, it's pretty simple right now so I've just included all the code. The dock appears just fine, I can resize it just fine also.
The problem is that when I try to drag it, it will not dock anywhere, even the place it just came from. It will turn into a floating window, but that's it.Thanks for any help.
@
ClockWidget::ClockWidget(QWidget *parent) : QFrame(parent)
{
QGridLayout *lay = new QGridLayout(this);theirTitleLabel = new QLabel(tr("Their")); qsoTitleLabel = new QLabel(tr("QSO")); utcLabel = new QLabel("Sun 00, 0000"); localLabel = new QLabel("Sun 00, 00:00mm"); theirLabel = new QLabel("Sun 00, 00:00mm"); qsoLabel = new QLabel("00:00:00"); lay->addWidget(new QLabel(tr("UTC")), 0, 0, Qt::AlignRight); lay->addWidget(utcLabel, 0, 1); lay->addWidget(new QLabel(tr("Local")), 1, 0, Qt::AlignRight); lay->addWidget(localLabel, 1, 1); lay->addWidget(theirTitleLabel, 2, 0, Qt::AlignRight); lay->addWidget(theirLabel, 2, 1); lay->addWidget(qsoTitleLabel, 3, 0, Qt::AlignRight); lay->addWidget(qsoLabel, 3, 1); setLayout(lay); updateClock();
}
void ClockWidget::updateClock()
{
QDateTime local = QDateTime::currentDateTime();
QDateTime utc = local.toUTC();utcLabel->setText(utc.toString("ddd dd, hh:mm")); localLabel->setText(local.toString("ddd dd, hh:mm"));
}
QDockWidget *ClockWidget::createDockWidget(QWidget *parent)
{
QDockWidget *dock = new QDockWidget(tr("Clock"), parent);
dock->setAllowedAreas(Qt::TopDockWidgetArea |
Qt::BottomDockWidgetArea |
Qt::LeftDockWidgetArea |
Qt::RightDockWidgetArea);
dock->setFeatures(QDockWidget::DockWidgetClosable |
QDockWidget::DockWidgetFloatable |
QDockWidget::DockWidgetMovable);
dock->setWidget(this);return dock;
}
@In my main window class (inherited from QMainWindow):
@
QDockWidget *dock;
clockWidget = new ClockWidget(this);
dock = clockWidget->createDockWidget(this);
addDockWidget(Qt::RightDockWidgetArea, dock);
toolsMenu->addAction(dock->toggleViewAction());
@That's a bit more complex than it needs to be but I was goofing around with things trying to make it work.
-
You can undock and dock the widget? For me I cannot dock the widget once it has been undocked. I found that if I comment out the line:
@dock->setWidget(this)@
then the dock frame can undock/dock just fine all day long. It has no content, but it can be moved around to any location, made floatable, re-docked, etc...
Any thoughts?
-
Ah, never mind. I figured it out. It seems that the widget is docked but when it undocks Qt doesn't think there is enough room in the main window for it to redock. If I make the window larger, it will then dock again. I just assumed that it came from the main window and it could then return to the main window but I guess that's not the case.
-
I have kind of the same problem like jeremy_c, only in my case everything workes great if I have the MainWindow in window mode. As soon as I set the window to fullscreen the docking will not work anymore. The interesting part is, that the location where the QDockWidget should dock has even more free space then it has in window mode?
I use the QDockWidget with QtDesigner and set all flags I need there.
Any suggestions?