Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Positioning a Dialog
Forum Updated to NodeBB v4.3 + New Features

Positioning a Dialog

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xargs1
    wrote on last edited by
    #1

    A Dialog seems to appear on the screen at the location where the application launched, which might be very far away from the application's current location. Dialog doesn't have an "anchors" property, and setting its x and y properties results in a dialog with no content. Is there any way to control the position of a Dialog?

    ? 1 Reply Last reply
    0
    • X xargs1

      A Dialog seems to appear on the screen at the location where the application launched, which might be very far away from the application's current location. Dialog doesn't have an "anchors" property, and setting its x and y properties results in a dialog with no content. Is there any way to control the position of a Dialog?

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @xargs1

      I don't know if this is the "right" way to do it but acting on the onVisibleChanged signal lets you position the dialog. What's odd is that onVisibleChanged gets triggered twice for on open() call. I don't get that.

      You could also make the dialog modal – on OSX at least, it anchors it to the app window.

      import QtQuick 2.5
      import QtQuick.Controls 1.4
      import QtQuick.Dialogs 1.2
      
      
      ApplicationWindow {
          id: appWindow
          visible: true
          width: 800
          height: 600
      
      
          Item {
              Dialog {
                  id: helloDialog
                  modality:Qt.NonModal
      
                  Label {
                      text: "Hello world!"
                  }
      
                  onVisibilityChanged: {
                      if (visible) {
                          console.log("visible", helloDialog.visible)
                          var xPos = (appWindow.x + appWindow.width /2) - helloDialog.width /2;
                          var yPos = (appWindow.y + appWindow.height /2) - helloDialog.height /2;
                          helloDialog.setX(xPos);
                          helloDialog.setY(yPos);
                      }
                  }
              }
          }
      
          Button {
              text: "Open"
              onClicked: {
                  helloDialog.open()
              }
          }
      }
      
      1 Reply Last reply
      1
      • X Offline
        X Offline
        xargs1
        wrote on last edited by
        #3

        That approach seems to work fine. It's strange that you need to jump through that extra hoop.

        Modality doesn't have any effect on Linux.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved