[英]Qml / Qt / C++ : QQuickView in a QWidget - Need Background Transparency
I am trying to get my container with a qquickview in it to be transparent, and only display the elements from the QML file without the background.我试图让我的带有 qquickview 的容器透明,并且只显示 QML 文件中的元素而没有背景。
Is there a nicer way to implement this?有没有更好的方法来实现这一点? Here is the relevant code, you can see I have commented out adding the QML to it so that the only offender is the QWidget containing a QQuickView这是相关的代码,你可以看到我已经注释掉了向其中添加 QML,因此唯一的违规者是包含 QQuickView 的 QWidget
The QML will make a menu similar to Apple's "Cover Flow" using only text. QML 将仅使用文本制作类似于 Apple 的“Cover Flow”的菜单。 I only want the text it generates to be visible.我只希望它生成的文本可见。
Currently it has a solid white background.目前它有纯白色背景。
QQuickView *view = new QQuickView();
QWidget *container = QWidget::createWindowContainer(view, this);
container->setObjectName("wrappingContainer");
container->setMinimumSize(1000, 240);
container->setMaximumSize(1000, 240);
container->setFocusPolicy(Qt::TabFocus);
//view->setSource(QUrl("qrc:/qml/wrappingMenu.qml"));
ui->testLayout->addWidget(container);
Try QQuickWidget
:试试QQuickWidget
:
#include <QtWidgets>
#include <QQuickWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget() {
setStyleSheet("background-color: 'grey';");
mQQuickWidget = new QQuickWidget(QUrl(QStringLiteral("main.qml")), this);
mQQuickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
mQQuickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
mQQuickWidget->setClearColor(Qt::transparent);
mQQuickWidget->resize(400, 400);
mQQuickWidget->raise();
}
private:
QQuickWidget *mQQuickWidget;
};
int main(int argc, char** argv)
{
QApplication app(argc, argv);
Widget widget;
widget.resize(400, 400);
widget.show();
return app.exec();
}
#include "main.moc"
import QtQuick 2.2
Item {
Text {
text: "Qt Quick Text"
font.pixelSize: 32
anchors.centerIn: parent
}
}
I doubt it could be done for a QQuickView
embedded in a QWidget
.我怀疑对于嵌入在QWidget
的QQuickView
是否可以做到。 But you can have a transparent QQuickView
like :但是你可以有一个透明的QQuickView
像:
QQuickView view;
view.setSurfaceType(QSurface::OpenGLSurface);
QSurfaceFormat format;
format.setAlphaBufferSize(8);
format.setRenderableType(QSurfaceFormat::OpenGL);
view.setFormat(format);
view.setColor(QColor(Qt::transparent));
view.setClearBeforeRendering(true);
view.setFlags(Qt::FramelessWindowHint);
view.setSource(QStringLiteral("qrc:/qml/wrappingMenu.qml"));
view.show();
You can do it with:你可以这样做:
QQuickView view;
view.setColor(Qt::transparent);
view.setSource("main.qml");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.