Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QWidget as QWindow for layer-shell-qt
QtWS25 Last Chance

Using QWidget as QWindow for layer-shell-qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
layer-shell-qtqwidgetqwindow
5 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    atomsky
    wrote on 29 Dec 2023, 09:25 last edited by
    #1

    I am trying to use a QWidget application as my desktop panel on Wayland. To that end, I am using layer-shell-qt. However, the LayerShellQt::Window::get(window) works on QWindow only. So, I have used windowHandle() to get the associated QWindow. The windowHandle() doesn't work if I don't show() the QWidget first. But if I show() the widget first, the size of the widget is not respected by the layer shell. (The widget covers the entire screen.) The show() has to come after the LayerShellQt commands for everything to work. The code below shows the hacky way I am doing it right now (show > hide > show).

    Is there a better way to do this? Is it necessary to show() a widget to get the window? Am I using LayerShellQt the wrong way?

    #include <LayerShellQt/Shell>
    #include <LayerShellQt/Window>
    #include <QApplication>
    #include <QWidget>
    #include <QWindow>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        uint barWidth = 30;
    
        LayerShellQt::Shell::useLayerShell();
        QApplication a(argc, argv);
    
        QWidget w;
        w.setStyleSheet("QWidget { background-color: teal; }");
        w.resize(barWidth, 600);
        w.show();
        w.hide();
    
        QWindow *lwin = w.windowHandle();
        qDebug() << lwin;
    
        if (LayerShellQt::Window *lsh = LayerShellQt::Window::get(lwin)) {
            qDebug() << lsh;
            lsh->setScope("atombar");
            lsh->setLayer(LayerShellQt::Window::LayerBottom);
            lsh->setExclusiveZone(barWidth);
            lsh->setAnchors(LayerShellQt::Window::AnchorRight);
        }
    
        w.show();
    
        return a.exec();
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Dec 2023, 10:07 last edited by
      #2

      Hi and welcome to devnet,

      That's a good question. I would recommend checking with the KDE folks that are handling that module.

      Out of curiosity, why do you need a QWidget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        atomsky
        wrote on 29 Dec 2023, 21:06 last edited by
        #3

        I want to make a panel/bar that displays workspace-specific taskbars. I need it as a visual indicator of where the opened programs are. In X11, I have tint2 that does it. I don't have a similar panel setup in wayland. To implement such a panel, my options were gtk-layer-shell and layer-shell-qt. I went with Qt.

        I built a prototype with QWidget that works with Hyprland. In the prototype, I used a QWidget filled with QVBoxLayouts. Each QVBoxLayout shows icons of the opened programs in the associated workspace. In the future, I want to implement "click to focus" and "drag to move" features as well.

        I am new to Qt, so I am not sure if this is the best way to do it. What do you suggest?

        S 1 Reply Last reply 31 Dec 2023, 22:18
        0
        • A atomsky
          29 Dec 2023, 21:06

          I want to make a panel/bar that displays workspace-specific taskbars. I need it as a visual indicator of where the opened programs are. In X11, I have tint2 that does it. I don't have a similar panel setup in wayland. To implement such a panel, my options were gtk-layer-shell and layer-shell-qt. I went with Qt.

          I built a prototype with QWidget that works with Hyprland. In the prototype, I used a QWidget filled with QVBoxLayouts. Each QVBoxLayout shows icons of the opened programs in the associated workspace. In the future, I want to implement "click to focus" and "drag to move" features as well.

          I am new to Qt, so I am not sure if this is the best way to do it. What do you suggest?

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 31 Dec 2023, 22:18 last edited by
          #4

          You could use QtQuick to build your GUI, that would make you avoid the use of QWidget and thus fit directly with the shell.

          Just from the top of my head but you could have a model with the icons of the applications and use something like a ListView to show them.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 1 Jan 2024, 01:40
          1
          • S SGaist
            31 Dec 2023, 22:18

            You could use QtQuick to build your GUI, that would make you avoid the use of QWidget and thus fit directly with the shell.

            Just from the top of my head but you could have a model with the icons of the applications and use something like a ListView to show them.

            A Offline
            A Offline
            atomsky
            wrote on 1 Jan 2024, 01:40 last edited by
            #5

            @SGaist Thanks for your suggestion. I will try to implement things with QtQuick.

            1 Reply Last reply
            0

            3/5

            29 Dec 2023, 21:06

            • Login

            • Login or register to search.
            3 out of 5
            • First post
              3/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved