PDA

View Full Version : QDockWidget pos, size problem



waynew
2nd March 2010, 00:15
I have a QDockWidget, properties are set like this;



helpWindow = new QDockWidget(this);
helpWindow->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);


When I close the window, I save the size and pos like this:



QPoint winPos = helpWindow->pos();
int xHelp = winPos.x();
int yHelp = winPos.y();

qDebug() << "Saving helpWindow pos: " << xHelp << yHelp;

QSize winSize = helpWindow->size();
int wHelp = winSize.width();
int hHelp = winSize.height();

QSqlDatabase db = QSqlDatabase::database(ctrlConn);
QSqlQuery query(db);
query.prepare("UPDATE settings set xHelp=?, yHelp=?, wHelp=?, hHelp=? where id=1");
query.addBindValue(xHelp);
query.addBindValue(yHelp);
query.addBindValue(wHelp);
query.addBindValue(hHelp);
query.exec();
close();


Here's the problem: the size saves correctly. The pos always saves as 0,63 regardless of the dock window position.

On restore, when the dock window is opened:



query.exec("SELECT xHelp, yHelp, wHelp, hHelp from settings where id = 1");
query.last();
int xHelp = query.value(0).toInt();
int yHelp = query.value(1).toInt();
int wHelp = query.value(2).toInt();
int hHelp = query.value(3).toInt();

qDebug() << "Restoring helpWindow pos: " << xHelp << yHelp;

if (xHelp + yHelp > 0) {
helpWindow->move(xHelp, yHelp);
helpWindow->resize(wHelp, hHelp);
}


Neither the size or the pos is restored properly. Even though the size is the saved size.

stefanadelbert
2nd March 2010, 00:36
QMainWindow::saveState should save the state and position of all of its QDockWidgets.

I'm having trouble with this functionality at the moment though. If I dynamically create a floating QDockWidget and then call QMainWindow::saveState, the dynamically created QDockWidget's details are not saved. However, if I dock the QDockWidget to the QMainWindow and then call QMainWindow::saveState, the QDockWidget's details are saved. The details are also saved if I float the QDockWidget again. Seems that actually docking the QDockWidget has some effect on the operation of QMainWindow::saveState.

waynew
2nd March 2010, 00:56
Sounds like the same problem to me. Seems like some reference is missing somewhere.

stefanadelbert
2nd March 2010, 02:17
I managed to solve my problem - I was incorrectly passing Qt::AllDockWidgetAreas to QMainWindow::addDockWidget, where I should have been passing Qt::LeftDockWidgetArea (or some other valid area).

I'm having other issues though, this time with QMainWindow::saveState when QDockWidgets are docked and tabbed. If I float one of the QDockWidgets and then try to QMainWindow::restoreState the floating QDockWidget state (docked and tabbed) is not restored and it is left floating. I'm stepping through the code at the moment and it seems that item.skip() in QDockAreaLayoutInfo::updateTabBar() is returning true for the floating QDockWidget, but I think this is a red herring. It's being skipped because it's not in the tab group because it's floating, where is should not be floating at the time this code is run.

I'm sure it's as a result of something that I'm doing wrong though. But I can't think what.

waynew
2nd March 2010, 23:02
Solved. The size and position I needed to save and restore were for the class, not the panel.