c++ - 带有 qt5 (qml) 的无框窗口

标签 c++ qt user-interface qml

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

我用 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

最佳答案

例如,这适用于 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
                }
            }
        }
    }
}

这是该项目的一个片段: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 确实有所作为:没有创建应用程序图标。

关于c++ - 带有 qt5 (qml) 的无框窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20860692/

相关文章:

macos - Cocoa:循环遍历窗口中的所有控件?

c++ - 为什么无论我输入什么,我的 "while"循环都会执行?

c++ - Qt C++ 信号槽不能正常工作

C++ - 方法和重载中的 const 关键字

qt - 如何在 QWizard 中完全禁用或隐藏后退按钮?

c++ - QT造物主: Program crashes in debug mode but working in Release mode and in DEBUG Mode with breakpoints for QThread based program

python - PyQt GUI 操作顺序

java - 空循环可以使用吗?

c++ - 是否为数组/vector 插入调用了赋值运算符或复制构造函数?

c++ - 如何使用SendMessage设置图片框样式