Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-119230

Setting the window position in Component.onCompleted does not update the dpi scale factor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 6.8
    • 6.6.0
    • macOS

    Description

      Our app saves its window position and on startup restores it from within Component.onCompleted.

      This worked with 6.5.3 but with 6.6.0 we have the following problem:
      When the app is closed on a Monitor with lower dpi and later reopened it is scaled to 200% (or whatever the scale factor for that monitor is).

      The following example replicates this behavior. It is a window with only a ToolBar in it. If the app opens on the lower dpi monitor, the toolbar is twice as large.

      import QtCore
      import QtQuick
      import QtQuick.Controls
      
      ApplicationWindow {
      	id: mainWindow
      	visible: true
      	width: 360
      	height: 320
      
      	Settings {
      		id: windowSettings
      		category: "Position"
      		property int x
      		property int y
      	}
      
      	Component.onCompleted: {
      		restorePosition();
      	}
      
      	function restorePosition(){
      		mainWindow.x = windowSettings.x;
      		mainWindow.y = windowSettings.y;
      	}
      
      	function savePosition(){
      		windowSettings.x = mainWindow.x
      		windowSettings.y = mainWindow.y
      	}
      
      	onXChanged: {Qt.callLater(savePosition)}
      	onYChanged: {Qt.callLater(savePosition)}
      
      	header: ToolBar {}
      }
      

      Reproduction steps:
      1. Create a new "Qt Quick Application" project in Qt Creator.
      2. Paste the code above into Main.qml.
      3. Run with Qt Creator on the high dpi monitor.
      4. Move the app window to the low dpi monitor and close it.
      5. Launch again -> App opens on last closed position but is incorrectly scaled.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vestbo Tor Arne Vestbø
            lbuckel Leon Buckel
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes