qt - StackView 项目被推到边界外
问题描述
我有以下主应用程序窗口的 QML 布局。我需要为无边框窗口创建阴影,这就是为什么内部矩形比应用程序边框小一点(我之前在 StackOverflow 上找到了这个解决方案)。问题是当一个新项目被推送到嵌套的 StackView 时,它会从内部矩形的外部移动。我应该如何解决它?
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
import org.b2soft.qml 1.0
ApplicationWindow {
id: window
visible: true
width: 800
height: 600
title: qsTr("Test")
color: "#00000000"
flags: Qt.FramelessWindowHint | Qt.Window
Rectangle {
id: rect
width: 700
height: 500
anchors.centerIn: parent
Column {
id: column
anchors.fill: parent
Row {
id: topbar
anchors.left: parent.left
anchors.right: parent.right
height: 24
Rectangle {
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width
color: "#37373a"
}
}
StackView {
id: rootStackView
anchors.left: parent.left
anchors.right: parent.right
height: parent.height - topbar.height
initialItem: Qt.resolvedUrl("login.qml")
}
Connections {
target: QMLWrapper
onLoginCompleted: rootStackView.push(Qt.resolvedUrl("main_stack.qml"))
}
}
}
DropShadow {
anchors.fill: rect
radius: 40
samples: 32
verticalOffset: 14
source: rect
color: "#40000000"
}
}
解决方案
我会冒险并假设这是默认的预期行为。默认情况下,QML 元素不会裁剪,因为担心这可能是一项繁重的操作。
并且堆栈视图通常包含在应用程序窗口内,因此这个问题不会很突出。
但是你的嵌套在一个较小的元素中,为工件的显现留出了空间。
您所要做的就是clip: true
为rect
.
推荐阅读
- indexing - 如果数组中的项目存在,则创建一个 couchdb 视图以进行索引
- python - Django:表单未显示
- android - 将 PagedListAdapter 与 LiveData 一起使用时如何显示空视图?
- asp.net-core - Swashbuckle.AspNetCore:“规范中没有定义操作!” 将“Microsoft.AspNetCore.Mvc.ApiExplorer”包更新到 2.2.0 后出现问题
- ruby-on-rails - AWS 的 MongoDB 性能问题
- java - bartMachine 在重复执行时会增加内存使用量
- typescript - 防止组合对象中的重复键,{ [K in keyof T]: T[K] } 的反转
- reactjs - 占位符未显示在下拉列表中,有人可以告诉我为什么吗?
- php - 如何在 PHP 中修复“未闭合元素 a”
- html - 在 div 与 h1 上设置字体大小的区别