Results 1 to 5 of 5

Thread: Fixing default Window position with move.

  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Fixing default Window position with move.

    Ok, I used QSettings to save the QPoint of where the user left the window before closing the window.

    When I relaunch the program, it does remember the last location the user kept the window, but it seems to add like 20 pixels to the Y position, so if I have a window maximized, after I close the program, the next time the program will be 20 pixels above where I last saved.

    I'm thinking it has something to do with my resolution. Is there a way to adjust it so, that it should stay exactly where the user saved according to their screen?
    like GetSystemMetrics kinda thing in Win API.

    I tried using: mapToGlobal(ptPos);
    But that's not what I want, it makes it relative to the top left of widget.

    I tried manually adjusting the Y, each time I call the settings. But that's usually a wrong offset, and not a good fix.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Fixing default Window position with move.

    Are you using Qt 4.2? Maybe QWidget::restoreGeometry() and QWidget::saveGeometry() would be sufficient for you?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Fixing default Window position with move.

    like this?
    Qt Code:
    1. Array = saveGeometry();
    2. settings.setValue("geometry", Array);
    3. // set the value on close.
    4.  
    5. //get value
    6. qbaArray = settings.value("geometry", QByteArray("10,10,10,10")).toByteArray();
    7. restoreGeometry(qbaArray);
    To copy to clipboard, switch view to plain text mode 

    I don't believe it worked. I am using 4.2.2
    Also, how did people do it before this method?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Fixing default Window position with move.

    Quote Originally Posted by VireX View Post
    like this?
    Qt Code:
    1. Array = saveGeometry();
    2. settings.setValue("geometry", Array);
    3. // set the value on close.
    4.  
    5. //get value
    6. qbaArray = settings.value("geometry", QByteArray("10,10,10,10")).toByteArray(); // <-- faulty
    7. restoreGeometry(qbaArray);
    To copy to clipboard, switch view to plain text mode 

    I don't believe it worked. I am using 4.2.2
    Sorry, what do you mean by "I don't believe it worked"? Does it work or not?

    Actually, the following is a bit faulty. QWidget uses more complex bytearray content for storing the geometries. QWidget validates the content of the passed byte array, though.
    Qt Code:
    1. qbaArray = settings.value("geometry",
    2. QByteArray("10,10,10,10")).toByteArray();
    To copy to clipboard, switch view to plain text mode 

    Also, how did people do it before this method?
    More or less how it's done in Window Geometry documentation. The more states (minimized, maximized, full screen) you want to take into, the more complex it gets. That's why QWidget::restoreGeometry() and QWidget::saveGeometry() were introduced.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    VireX (3rd April 2007)

  6. #5
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Fixing default Window position with move.

    I think it worked, I didn't believe because my program was crashing, so I didn't know if it was the geometry, or something else I had changed. It wasn't the geometry.

Similar Threads

  1. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  2. Model Drag'n'Drop - Default Move
    By Lemming in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2006, 21:46
  3. move qTextBrowser to Home Position
    By klaus1111 in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2006, 13:09
  4. Move window in Clone Mode
    By ultrabrite in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2006, 18:22
  5. positioning a window at a specific screen position
    By nupul in forum Qt Programming
    Replies: 3
    Last Post: 29th March 2006, 20:21

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.