frameless windows with qt5 (qml)

AsfK picture AsfK · Dec 31, 2013 · Viewed 17.5k times · Source

I spent some good hours on web searching but nothing help me..

I build GUI with QML and I want him without frame.

I tried to change my main.cpp like this:

#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();
}

I also tried to change main.qml file:

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

    // my qml code here
}

but nothing work.

I'll glad for any help, thanks!

I work with:

  • Win 7 x64
  • Qt 5.1.1

Answer

pepper_chico picture pepper_chico · Jan 1, 2014

This for example, works on 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
                }
            }
        }
    }
}

It's an snippet from this project: https://github.com/oblitum/backlight/tree/cpp

Initially I was using Qt.SplashScreen | Qt.FramelessWindowHint but it didn't make a difference for me on Ubuntu (others also use Qt.SubWindow | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint), so I left only Qt.FramelessWindowHint. It may make a difference for you.

This is Qt 5.2.

EDIT

Nevermind, Qt.SplashScreen did make a difference: no application icon is created.