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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With