Results 1 to 4 of 4

Thread: How to use QSetting for different resolutions.

  1. #1
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to use QSetting for different resolutions.

    Hi Friends,

    I am using QmainWindow with tool bar and the dockwidgets. I have used QSetting to save and load the state.

    But I am facing one problem:

    - I have saved my window layout with some resolution (say 1280 X 1024) then I am able to retrieve it while loading. But when the system resolution is set other then the previous one (say 800 X 600) then I am not able to retrieve the proper format. Same happen vice verse...

    What I am missing??? I have used save setting and load setting as:

    Qt Code:
    1. void MyMainWindow::writeSettings()
    2. {
    3. QSettings settings("workspace/myapp.ini", QSettings::IniFormat);
    4.  
    5. settings.beginGroup("MyMainWindow");
    6.  
    7. settings.setValue("geometry", saveGeometry());
    8. settings.setValue("state", saveState());
    9.  
    10. settings.sync();
    11.  
    12. settings.endGroup();
    13. }
    14.  
    15. void MyMainWindow::readSettings()
    16. {
    17. //QSettings settings("SKU", "MY Main Window");
    18. QSettings settings("workspace/myapp.ini", QSettings::IniFormat);
    19.  
    20. settings.beginGroup("MyMainWindow");
    21.  
    22. restoreGeometry(settings.value("geometry").toByteArray());
    23. restoreState(settings.value("state").toByteArray());
    24.  
    25. settings.endGroup();
    26. }
    To copy to clipboard, switch view to plain text mode 

    Note: I am using frame less window (It's a need).


    Thanks...

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to use QSetting for different resolutions.

    From QWidget::restoreGeometry():
    If the restored geometry is off-screen, it will be modified to be inside the available screen geometry.
    You cannot fit a window sized at 1280x1024 into 800x600 without changing anything so it's likely that Qt is resizing/moving to fit. It is not clear from your post exactly what "proper format" should be. If your layout becomes unusable at 800x600 then you need to address this (or set a lower screen-size limit) with layout management and scroll areas etc.

  3. #3
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to use QSetting for different resolutions.

    Quote Originally Posted by ChrisW67 View Post
    From QWidget::restoreGeometry():


    You cannot fit a window sized at 1280x1024 into 800x600 without changing anything so it's likely that Qt is resizing/moving to fit. It is not clear from your post exactly what "proper format" should be. If your layout becomes unusable at 800x600 then you need to address this (or set a lower screen-size limit) with layout management and scroll areas etc.
    Hi ChrisW67, Thanks for the reply.

    Actually I have 3 dockwidget in my application.

    1- MainDock
    2- Left
    3- Bottom

    I have given more space to the "MainDock" [around 3/4 * width() and 3/4 * height()].

    But while saving it using "writeSettings(...)" function in resolution "1280x1024" and opening the application in "800 x 600", I did not found the spacing what I have saved in the "1280x1024" resolution [At least ratio wise]

    Is there any way to maintain the layout using QSetting for different resolutions.

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use QSetting for different resolutions.

    QSettings doesn't have a brain; it only stores positions and sizes. When you make the geometry calls, they're smart enough to place things so they're still onscreen, but that's the limit of their intelligence.

    If you want to duplicate your original layout at a different size, you'll have to retrieve the raw settings and do the computations yourself. Qt's QRect class and related ones can help here.

Similar Threads

  1. Replies: 3
    Last Post: 20th December 2008, 00:12
  2. Replies: 9
    Last Post: 25th January 2008, 17:43
  3. QVector and QSetting
    By mattia in forum Newbie
    Replies: 1
    Last Post: 8th November 2007, 16:21
  4. QSetting value() not correct
    By bpetty in forum Newbie
    Replies: 1
    Last Post: 14th August 2006, 19:58
  5. Dialog sizes and different screen resolutions.
    By hvengel in forum Qt Tools
    Replies: 3
    Last Post: 2nd April 2006, 10:05

Tags for this Thread

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.