我想做一个游戏覆盖,以显示我的自定义十字线。我希望它始终在那里,没有关闭策略。
我在ApplicationWindow
中使用了Popup
项,并将它的不透明度设置为0
,将弹出窗口的不透明度设置为1
,但它什么都没有显示。我也尝试在没有任何顶层窗口的情况下使用弹出项,但同样什么都没有。
问题是“有没有可能在没有任何可见的顶层窗口的情况下显示一个总是在顶端的弹出窗口?”
您的建议将不胜感激。
发布于 2020-05-21 11:02:37
如果没有弹出窗口,我们可以尝试使用QQuickItem的'z‘属性。总是把十字准线堆在你的其他物品上面。如果你想在屏幕上移动十字准线,你可以使用它们的“x,y”属性。
我已经尝试了一个简单的样本来做同样的事情。已将图像项目用于滚动视图顶部的十字准线。它的工作方式与预期一致。我试过我的方法了。我们将看看是否会有其他想法出现。
示例代码如下:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
// used here only to indicate image loading is going on
BusyIndicator {
id: busyindicatorId
visible: backgroundImgId.status === Image.Loading ||
crossImgId.status === Image.Loading
anchors.centerIn: parent
}
// background item
ScrollView {
anchors.fill: parent
anchors.margins: 10
clip: true
visible: !busyindicatorId.visible
Image {
id: backgroundImgId
source: "https://i.ibb.co/ZBNLvzb/andriod.jpg"
}
}
// crosshair item
Image {
id: crossImgId
z: 1
width: 100
height: width
visible: !busyindicatorId.visible
source: "https://i.ibb.co/SJFTLwN/cross.png"
anchors.centerIn: parent
}
}
更新实例化的两个窗口,其中一个可以用于十字准线,并且必须设置一些窗口属性(透明,总是在顶部)以始终显示在顶部。让我们来看看这段基本代码。示例video
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
#include <QScreen>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
QScreen *screen = QGuiApplication::primaryScreen();
QQuickView view;
view.setSource(QUrl(QStringLiteral("qrc:/crosshair.qml")));
view.setX(screen->geometry().width()/2 - view.width()/2);
view.setY(screen->geometry().height()/2 - view.height()/2);
view.setColor("transparent");
view.setFlags(Qt::SubWindow | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
view.show();
return app.exec();
}
//////////////// main.qml ////////////////
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
visibility: "FullScreen"
objectName: "mainWindow"
// used here only to indicate image loading is going on
BusyIndicator {
id: busyindicatorId
visible: backgroundImgId.status === Image.Loading
anchors.centerIn: parent
}
// background item
ScrollView {
anchors.fill: parent
anchors.margins: 10
clip: true
visible: !busyindicatorId.visible
Image {
id: backgroundImgId
source: "https://i.ibb.co/ZBNLvzb/andriod.jpg"
}
}
}
//////////////// crosshair.qml ////////////////
import QtQuick 2.9
import QtQuick.Controls 2.2
Item {
width: 100
height: 100
// crosshair item
Image {
width: parent.width
height: parent.height
source: "https://i.ibb.co/SJFTLwN/cross.png"
}
}
https://stackoverflow.com/questions/61855075
复制相似问题