- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个 Popup
modal覆盖整个根 ApplicationWindow
, 但我想在我正在构建的小部件容器中实例化此 Popup
,它将深度嵌套在 QML 层次结构中。不幸的是,实例化一个不是 ApplicationWindow
的直接子级并且滚出 View 的 Popup
不会居中并覆盖 ApplicationWindow
。
在下面的代码中,我在子 Item
中实例化了一个 Popup
,但我不知道如何让它在视口(viewport)上居中:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
id: root;
visible: true
width: 100
height: 150
Flickable {
id: flickable;
contentHeight: col_layout.height;
anchors.fill: parent;
ColumnLayout {
id: col_layout;
Rectangle {color:'green'; width:100; height: 100}
Rectangle {color:'red'; width:100; height: 100;
Popup{
id: popup;
modal: true;
visible: true;
Rectangle{ color:'blue'; width:200; height: 200; }
}
}
}
MouseArea {
anchors.fill: parent;
onClicked: {
popup.open();
popup.visible = true;
}
}
}
}
这会产生(蓝色 Rectangle
是模态内容):
我必须在 ApplicationWindow
的全局范围内放置一个 Popup
还是有一些方法可以实例化和控制 Popup
一些子 Item
或模块?
我已经尝试将 Popup
的 parent
属性设置为 root
但无济于事。我真的很想避免将所有可能的弹出窗口都塞进根 ApplicationWindow
。
最佳答案
您不能将 Popup
的父级设置为 root
,因为 root
不是 Item
-类型。因此它不能是parent
。
但是,您可以将它作为 root.contentItem
的父级。
因为您可能会在其他文件中声明 Popup
,因此可能会隐藏 id: root
,因此我会投票赞成使用附加属性 ApplicationWindow
相反,如果您使用它,它是可用的。
Popup {
id: popup;
modal: true;
visible: true;
parent: ApplicationWindow.contentItem // This will do the trick
Rectangle{ color:'blue'; width:200; height: 200; }
}
关于qt - 如何将 Popup 添加到嵌套项目内的根 ApplicationWindow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44684135/
我想恢复主控“main.qml”的位置和大小。但我不知道如何声明新窗口的父窗口。如果我直接从 javascript 中的窗口 main.qml 打开窗口,我没有问题,但通过 python 我不知道如何
让我们考虑这个代码片段: ApplicationWindow { /**/ states: State {} /**/ } 运行应用程序时,我得到 Cannot assign
我正在编译一个开源备份应用程序。我希望不要使用 X 或任何组合键(例如 Windows 中的 Alt+F4)关闭应用程序。在这种情况下,我更喜欢将应用程序最小化到系统托盘。 我是 Java 新手,到目
我正在使用 Python 3.6,我正尝试从 glade xml 文件创建一个应用程序窗口,如下所示: builder = Gtk.Builder() builder.add_from_file("u
我在尝试从一个 ApplicationWindow 切换到另一个时遇到了这个问题。 我有一个名为 login.qml 的第一个窗口,它通过以下信号打开 main.qml: onIdAutenticad
我使用 JFace 的 ApplicationWindow 创建了一个简单的窗口,并尝试添加菜单栏。 public MainWindow() { super(null); this.a
有没有人在使用 ApplicationWindow 时能够热重载所有 QML 文件? ?我发现了一些例子,如 https://qml.guide/live-reloading-hot-reloadin
我想创建一个 Popup modal覆盖整个根 ApplicationWindow , 但我想在我正在构建的小部件容器中实例化此 Popup ,它将深度嵌套在 QML 层次结构中。不幸的是,实例化一个
我想创建一个 Popup modal覆盖整个根 ApplicationWindow , 但我想在我正在构建的小部件容器中实例化此 Popup ,它将深度嵌套在 QML 层次结构中。不幸的是,实例化一个
我用一个 main.qml 创建了一个简单的 Qt 快速应用程序,就像下面的代码。问题是窗口的背景颜色没有设置为 #ffffff ,而是设置为浅灰色(我认为是 Windows 上窗口的默认颜色)。矩形
我有一个名为 main.qml 的文件,它实例化了 ApplicationWindow . 我想在其他 qml 文件中访问这个对象(应用程序)。 ApplicationWindow { id:
我想默认将我的应用程序设置为 180 度方向。在 ApplicationWindow 级别旋转屏幕的 API 是什么?我的应用程序中有工具栏和状态栏,因此我需要旋转 ApplicationWindow
我想默认将我的应用程序设置为 180 度方向。在 ApplicationWindow 级别旋转屏幕的 API 是什么?我的应用程序中有工具栏和状态栏,因此我需要旋转 ApplicationWindow
如何在 C++ 中获取 QML ApplicationWindow 的大小? QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral
如何正确扩展 QML ApplicationWindow 类型?根据文档,ApplicationWindow 实例化了一个 QQuickWindow。所以我尝试从 QQuickWindow 进行子类化
我在为用 QtQuick 编写的应用程序绑定(bind)“关闭时”事件时遇到问题。我想做的是执行标准的“确认退出”方法,也许我的做法是错误的。 据我了解,我想要类似的东西 void MainDrive
我像这样测试一个简单的 QML(Qt sdk 版本 5.3.2)程序 import QtQuick 2.3 import QtQuick.Controls 1.2 ApplicationWindow
默认情况下,Qml 控件带有一个很好的类似原生的主题。当我通过解释器将我的程序作为 qml 文件运行时,它看起来很棒,但是,一旦我将我的代码复制到 C++ 后端并构建它,它看起来完全没有主题而且非常平
我想使用 ApplicationWindow 作为主文件,并能够使用 从 C++ 切换到其他 QML 文件>QQuickView::setSource(const QUrl & url)。基本上它会这
我是 Qt quick control 2 开发的新手。我正在为 android 开发一个跨平台应用程序。我正在从 C++ 代码加载新屏幕,如下所示 int main(int argc, char *
我是一名优秀的程序员,十分优秀!