【问题标题】:frameless windows with qt5 (qml) [duplicate]带有qt5(qml)的无框窗口[重复]
【发布时间】:2014-01-18 14:05:37
【问题描述】:

我花了一些时间在网络搜索上,但没有任何帮助..

我用 QML 构建 GUI,我希望他没有框架。

我尝试像这样更改我的 main.cpp:

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

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

    viewer.setMainQmlFile(QStringLiteral("qml/RR_QML/main.qml"));
    viewer.setFlags(Qt::FramelessWindowHint | Qt::Window);
    viewer.showExpanded();

    return app.exec();
}

我也尝试更改 main.qml 文件:

Window
{
    id: rootWindow
    flags: Qt.FramelessWindowHint | Qt.Window

    // my qml code here
}

但没有任何效果。

我很乐意为您提供任何帮助,谢谢!

我与:

  • Win 7 x64
  • Qt 5.1.1

【问题讨论】:

  • 你试过没有应用程序查看器的“原生”QQuickView,以防万一吗?
  • @LaszloPapp:我还没试过。实际上我是Qt的新手,你能指导我怎么做吗?谢谢!
  • Qt 自己的无框架“形状时钟”示例是否按预期工作? qt-project.org/doc/qt-5.1/qtwidgets/widgets-shapedclock.html

标签: c++ qt user-interface qml


【解决方案1】:

例如,这适用于 Ubuntu:

import QtQuick 2.2
import QtQuick.Window 2.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1

ApplicationWindow {
    id: backlight
    flags: Qt.FramelessWindowHint
    visible: true
    title: qsTr("backlight")
    width: 500
    height: 50
    x: (Screen.width - width) / 2
    y: (Screen.height - height) / 2
    color: "transparent"

    property real slideValue
    signal onSlide(real value)

    Rectangle {
        anchors.centerIn: parent
        width: parent.width
        height: 50
        color: "transparent"

        Rectangle {
            anchors.fill: parent
            radius: 25
            opacity: 0.3
            color: "gray"
        }

        Slider {
            anchors.centerIn: parent
            width: backlight.width - 16
            height: backlight.height
            value: backlight.slideValue
            focus: true
            onValueChanged: backlight.onSlide(value)
            Keys.onSpacePressed: Qt.quit()
            Keys.onEscapePressed: Qt.quit()

            style: SliderStyle {
                groove: Rectangle {
                    implicitHeight: 8
                    radius: 4
                    color: "gray"
                }
                handle: Rectangle {
                    anchors.centerIn: parent
                    color: control.pressed ? "white" : "lightgray"
                    border.color: "gray"
                    border.width: 2
                    width: 34
                    height: 34
                    radius: 17
                }
            }
        }
    }
}

这是来自这个项目的 sn-p:https://github.com/oblitum/backlight/tree/cpp

最初我使用的是Qt.SplashScreen | Qt.FramelessWindowHint,但在 Ubuntu 上对我没有任何影响(其他人也使用Qt.SubWindow | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint),所以我只留下了Qt.FramelessWindowHint。它可能会对您产生影响。

这是 Qt 5.2。

编辑

没关系,Qt.SplashScreen 确实有所作为:没有创建应用程序图标。

【讨论】:

  • 我没有成功运行这个,可能是因为我使用的是 QT 5.0。我将安装 Qt 5.2 并重试。非常感谢!
  • 这两个标志都不适合我。 :( 赢 7 x64,Qt 5.1.1,MinGW 4.8.0
  • @QinPeixi 此标志/QML 元素将在 Qt 5.2 上使用
  • 它有效,但仅适用于 Qt 5.2。也许他们在 Qt 5.0 上有错误。所以将你的 Qt 更新到 5.2 并享受:)
  • 在 OSX 上测试,完美运行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-30
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多