1

I need to have a Popup that stays visible outside the bounds of the main window. I couldn't find anything in the Qt documentation.

This is the code:

import QtQuick 2.15
import QtQuick.Window 2.2
import QtQuick.Controls 2.12

ApplicationWindow {
    id: window
    width: 400
    height: 400
    visible: true

    Button {
        text: "Open"
        onClicked: popup.open()
    }

    Popup {
        id: popup
        x: 100
        y: 100
        width: 300
        height: 400
        modal: true
        focus: true
        dim: false

        contentItem: Rectangle
        {
            anchors.fill: parent
            color: "red"
        }

        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
    }
}

This is the output of this: enter image description here

I want the red to go beyond the window borders. Something like this: enter image description here

I'd appreciate the help!

Note: using a Dialog is no good for me.

Haj Ayed Amir
  • 187
  • 4
  • 14
  • Ok, I see you've copied the code from the documentation page. So you have to check the paragraph below that, especially the top/left insets. Actually you set x,y properties as 100,100 and so QML does exactly you asked to do. if you want it in the window borders, change it to 0,0 – folibis Apr 06 '22 at 10:15
  • @folibis I need the red to go outside the window. I added an image to illustrate. – Haj Ayed Amir Apr 06 '22 at 11:05
  • I think you want to [open a new window](https://stackoverflow.com/questions/1518317/how-to-show-another-window-from-mainwindow-in-qt) – Michael Kotzjan Apr 06 '22 at 11:13

1 Answers1

2

Popups are not proper windows, so you'd need to create a new window like Michael mentioned:

import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow {
    id: mainWindow
    width: 640
    height: 480
    visible: true

    ApplicationWindow {
        id: redWindow
        x: mainWindow.x + mainWindow.width / 2
        y: mainWindow.y + mainWindow.height / 2
        width: 300
        height: 400
        flags: Qt.Popup | Qt.Dialog
        visible: true

        Rectangle {
            color: "red"
            anchors.fill: parent
        }
    }
}

There is a suggestion to make Popups proper windows here.

Mitch
  • 23,716
  • 9
  • 83
  • 122