2

I'm developing a note application with PySide6 on Ubuntu 22.04. The note windows should be like usual windows, but they should have no taskbar entry.

I tried already multiple approaches, including the answers from Hide PyQt app from taskbar. It seems they are fine for single window apps, but have some caveats for multi window apps. Here is how far I got:

import sys
from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *

class NoteWindow(QFrame):
    i = 1

    def __init__(self):
        super().__init__()
        self.setWindowFlags(Qt.Tool)
        self.setWindowTitle(str(self.i))
        NoteWindow.i += 1
        self.show()

app = QApplication([])
w1 = NoteWindow()
w2 = NoteWindow()

# close the app after 10 seconds
close_timer = QTimer()
close_timer.singleShot(10000, app.quit)

sys.exit(app.exec())

There is no taskbar entry, but the second window is always in front of the first one. I would like to have the clicked window in front (I think this is the usual window behavior).

Do you have any ideas? Ideally it should work cross-platform.

Marph
  • 176
  • 4
  • 15
  • 1
    I'm not a python guy, so I don't fully understand your example, but could this be at least part of the problem? From the docs: If there is a parent, the tool window will always be kept on top of it. Also, have you looked at Qt::FramelessWindowHint? – mzimmers Feb 25 '23 at 19:14
  • Both windows don't have a parent. So in theory it shouldn't matter. Just to make sure, I tried with an explicit parent, with the same result. I'm using `Qt::FramelessWindowHint`, but in another context. It hides the titlebar. So it doesn't have an effect on this particular problem. I tried `Qt::BypassWindowManagerHint`, too. It resolved the "internal" ordering problem, but then the note windows were on top of everything else always. FTR: [windowtype doc](https://doc.qt.io/qt-6/qt.html#WindowType-enum) – Marph Feb 26 '23 at 16:36
  • Does this answer your question? [Qt Hide Taskbar Item](https://stackoverflow.com/questions/4055506/qt-hide-taskbar-item) – relent95 Feb 27 '23 at 14:29
  • Unfortunately no. I will try to add all tried approaches to the question. After reading [this comment](https://stackoverflow.com/questions/4055506/qt-hide-taskbar-item#comment111774836_4056292), I fear that tinkering with X11 is necessary to get it to work on my machine. – Marph Feb 27 '23 at 17:25
  • What do you mean by _There is no taskbar entry, but the second window is always in front of the first one. I would like to have the clicked window in front (I think this is the usual window behavior)._ I tried both your scripts and I got practically the same result: No taskbar, one window upon the other, but when shifted away I can select either of the two. I'm not understading the point – Buzz Mar 01 '23 at 14:34
  • @Buzz: The point is: When the windows are overlapping and you click at one of them, it should come to front. This doesn't work for me _on Ubuntu 22.04_. On windows, the script mentioned in the question works. – Marph Mar 01 '23 at 15:55
  • Sorry @Marph, I missed the OS you were working on – Buzz Mar 01 '23 at 16:03

1 Answers1

0

Thanks to the comments, I was able to get it to work on my machine:

import shutil
import subprocess
from PySide6.QtWidgets import *
from PySide6.QtCore import *

class NoteWindow(QFrame):
    def __init__(self):
        super().__init__()
        if shutil.which("xprop") is not None:
            # Workaround to get multiple windows without task bar on X11.
            subprocess.check_call([
                "xprop",
                "-f", "_NET_WM_STATE", "32a",
                "-id", str(self.winId()),
                "-set", "_NET_WM_STATE", "_NET_WM_STATE_SKIP_TASKBAR",
            ])
        self.show()

app = QApplication([])
w1 = NoteWindow()
w2 = NoteWindow()

# close the app after 10 seconds
close_timer = QTimer()
close_timer.singleShot(15000, app.quit)

app.exec()

However, messing around with the window manager is not nice and not cross-platform. Maybe there is a better way, so I'm leaving the question open.

Marph
  • 176
  • 4
  • 15
  • Welcome to the wonderful world of open source! Window managers just *exist*: they *may* follow the known implementation, but there's no guarantee that they'll actually do it. Their behavior may be inconsistent or not "generally" accepted. You can only live with it and: 1. test using VMs (hoping that different versions of the same WM doesn't implicate inconsistency); 2. hope other WM you didn't consider don't override the "requested" behavior. The real question you should probably try to ask is: what is the *actual* order those windows should respect? And how that should be triggered? – musicamante Mar 01 '23 at 04:20