Results 1 to 5 of 5

Thread: QDockWidget pos, size problem

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QDockWidget pos, size problem

    I have a QDockWidget, properties are set like this;

    Qt Code:
    1. helpWindow = new QDockWidget(this);
    2. helpWindow->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. QPoint winPos = helpWindow->pos();
    2. int xHelp = winPos.x();
    3. int yHelp = winPos.y();
    4.  
    5. qDebug() << "Saving helpWindow pos: " << xHelp << yHelp;
    6.  
    7. QSize winSize = helpWindow->size();
    8. int wHelp = winSize.width();
    9. int hHelp = winSize.height();
    10.  
    11. QSqlDatabase db = QSqlDatabase::database(ctrlConn);
    12. QSqlQuery query(db);
    13. query.prepare("UPDATE settings set xHelp=?, yHelp=?, wHelp=?, hHelp=? where id=1");
    14. query.addBindValue(xHelp);
    15. query.addBindValue(yHelp);
    16. query.addBindValue(wHelp);
    17. query.addBindValue(hHelp);
    18. query.exec();
    19. close();
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. query.exec("SELECT xHelp, yHelp, wHelp, hHelp from settings where id = 1");
    2. query.last();
    3. int xHelp = query.value(0).toInt();
    4. int yHelp = query.value(1).toInt();
    5. int wHelp = query.value(2).toInt();
    6. int hHelp = query.value(3).toInt();
    7.  
    8. qDebug() << "Restoring helpWindow pos: " << xHelp << yHelp;
    9.  
    10. if (xHelp + yHelp > 0) {
    11. helpWindow->move(xHelp, yHelp);
    12. helpWindow->resize(wHelp, hHelp);
    13. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDockWidget pos, size problem

    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.

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDockWidget pos, size problem

    Sounds like the same problem to me. Seems like some reference is missing somewhere.

  4. #4
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDockWidget pos, size problem

    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.

  5. #5
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDockWidget pos, size problem

    Solved. The size and position I needed to save and restore were for the class, not the panel.

Similar Threads

  1. QDockWidget - dynamic size
    By ttvo in forum Qt Programming
    Replies: 3
    Last Post: 12th June 2009, 07:07
  2. QDockWidget size
    By user in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2009, 20:35
  3. Default size of a QListWidget inside a QDockWidget
    By rakuco in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 08:01
  4. QDockWidget Size
    By kiker99 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2007, 16:15
  5. QDockWidget fixed size?
    By Michiel in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2006, 02:48

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
  •  
Qt is a trademark of The Qt Company.