Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

frameless windows with qt5 (qml) [duplicate]

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
like image 739
AsfK Avatar asked Dec 31 '13 16:12

AsfK


1 Answers

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.

like image 170
pepper_chico Avatar answered Nov 05 '22 09:11

pepper_chico