Skip to content
Advertisement

How to apply ‘Qt.WA_X11NetWmWindowTypeDesktop’ attribute to my QML window by using PyQt5

I am working on a desktop environment and I want my QML window as my main desktop window. I am integrating QML with PyQt5.

here is my code

JavaScript

main.qml

JavaScript

main2.qml

JavaScript

I tried adding window.setAttribute(Qt.WA_X11NetWmWindowTypeDesktop, True) in code but it doesn’t work. Also I tried adding Qt.Desktop flag also this doesn’t work. At the first time, it gave me error AttributeError: ‘QQuickWindow’ object has no attribute ‘setAttribute’. In second attempt the script ran successfully but window didn’t open. I thought it may be because another desktop window is running. So I loggend into an another console with my user name, created a bash file to run window manager and dektop window, then start it by startx /home/newtron/myscript. It opened a blank window. There wasn’t even mouse(may be a failure).

can anybody help me?

thanks.

Advertisement

Answer

Qt::WA_X11NetWmWindowTypeDesktop is a Qt::WidgetAttribute so it only makes sense for the QWidget and it seems that the OP understands it because in its attempt it uses a QMainWindow but the problem is that the QMainWindow does not show the QML so that is not the solution.

The idea is to have a QWidget where the QML is so in this case there are 2 possible solutions:

  1. Set visible: false in ApplicationWindow and use QWidget::createWindowContainer():

    JavaScript

    main.qml

    JavaScript
  2. QQuickView with QWidget::createWindowContainer():

    JavaScript

    main.qml

    JavaScript
  3. QQuickWidget:

    JavaScript

    main.qml

    JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement