gpt4 book ai didi

Qt5 & QtQuick2 - 透明主窗口

转载 作者:行者123 更新时间:2023-12-04 08:52:44 25 4
gpt4 key购买 nike

我正在尝试创建一个带有无框窗口和圆角的简单 Qt UI。从带有 QtQuick 2 应用程序模板的新项目开始,我的代码如下所示:

主程序

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

QtQuick2ApplicationViewer viewer;

viewer.setMainQmlFile(QStringLiteral("qml/qtquick-test/main.qml"));
viewer.setFlags(Qt::FramelessWindowHint);
viewer.showExpanded();

return app.exec();
}

主文件
import QtQuick 2.0

Rectangle {
width: 360
height: 360
radius: 10
color: "red"

Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}

这是结果:

And this is the result

我不想做的是通过使主窗口透明来摆脱白色角落。但是,据我所知,在 Qt5 中没有办法做到这一点,因为我们没有样式表等,而且我没有使用 QtWidget。我应该使用 QtWidget 吗?

顺便说一句,我是 Qt 和 Qt5 的新手。

最佳答案

这在 Windows 8 和 Ubuntu 12.04 下对我有用。

import QtQuick 2.3
import QtQuick.Window 2.2

Window {
width: 300
height: 300
flags: Qt.FramelessWindowHint | Qt.Window
color: "transparent"

Rectangle {
color: "brown"
anchors.fill: parent
anchors.margins: 10
}
}

关于Qt5 & QtQuick2 - 透明主窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14780504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com