Fix popup positions to stay inside window.
This commit is contained in:
parent
bc836944f2
commit
37db0a2394
2 changed files with 16 additions and 15 deletions
|
|
@ -72,24 +72,24 @@ Button {
|
||||||
closePolicy: Popup.CloseOnPressOutsideParent | Popup.CloseOnPressOutside | Popup.CloseOnEscape
|
closePolicy: Popup.CloseOnPressOutsideParent | Popup.CloseOnPressOutside | Popup.CloseOnEscape
|
||||||
padding: 10 * DefaultStyle.dp
|
padding: 10 * DefaultStyle.dp
|
||||||
parent: mainItem // Explicit define for coordinates references.
|
parent: mainItem // Explicit define for coordinates references.
|
||||||
|
function updatePosition(){
|
||||||
onVisibleChanged: {
|
|
||||||
if (!visible) return
|
if (!visible) return
|
||||||
// Do not use popup.height as it is not consistent.
|
var popupHeight = popup.height + popup.padding
|
||||||
var popupHeight = mainItem.height + popup.implicitContentHeight + popup.padding
|
var popupWidth = popup.width + popup.padding
|
||||||
var position = mainItem.mapToItem(mainItem.Window.contentItem, mainItem.x + popup.implicitContentWidth + popup.padding, mainItem.y + popupHeight)
|
var winPosition = mainItem.Window.contentItem.mapToItem(mainItem,0 , 0)
|
||||||
if (position.y + popupHeight >= mainItem.Window.height) {
|
|
||||||
y = -popupHeight
|
y = Math.max( Math.min( winPosition.y + mainItem.Window.height - popupHeight, mainItem.height), winPosition.y)
|
||||||
}else {
|
x = Math.max( Math.min( winPosition.x + mainItem.Window.width - popupWidth, 0), winPosition.x)
|
||||||
y = mainItem.height + popup.padding
|
|
||||||
}
|
|
||||||
if (position.x >= mainItem.Window.width) {
|
|
||||||
x = mainItem.width - Math.max(popup.width, popup.implicitContentWidth)
|
|
||||||
} else {
|
|
||||||
x = 0
|
|
||||||
}
|
|
||||||
popup.contentItem.forceActiveFocus()
|
popup.contentItem.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
onHeightChanged: Qt.callLater(updatePosition)
|
||||||
|
onWidthChanged: Qt.callLater(updatePosition)
|
||||||
|
Connections{
|
||||||
|
target: mainItem.Window
|
||||||
|
function onHeightChanged(){ Qt.callLater(popup.updatePosition)}
|
||||||
|
function onWidthChanged(){ Qt.callLater(popup.updatePosition)}
|
||||||
|
}
|
||||||
|
onVisibleChanged: Qt.callLater(updatePosition)
|
||||||
|
|
||||||
background: Item {
|
background: Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
|
||||||
|
|
@ -369,6 +369,7 @@ Item {
|
||||||
popup.contentItem: FocusScope {
|
popup.contentItem: FocusScope {
|
||||||
id: popupFocus
|
id: popupFocus
|
||||||
implicitHeight: settingsButtons.implicitHeight
|
implicitHeight: settingsButtons.implicitHeight
|
||||||
|
implicitWidth: settingsButtons.implicitWidth
|
||||||
Keys.onPressed: (event)=> {
|
Keys.onPressed: (event)=> {
|
||||||
if (event.key == Qt.Key_Left || event.key == Qt.Key_Escape) {
|
if (event.key == Qt.Key_Left || event.key == Qt.Key_Escape) {
|
||||||
settingsMenuButton.popup.close()
|
settingsMenuButton.popup.close()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue