Qt Hide Taskbar Item
Asked Answered
M

4

28

I have a custom QWidget and I simple don't want it to show up in the taskbar. I have a QSystemTrayIcon for managing exiting/minimizing etc.

Monoploid answered 29/10, 2010 at 20:8 Comment(0)
F
24

I think the only thing you need here is some sort of parent placeholder widget. If you create your widget without a parent it is considered a top level window. But if you create it as a child of a top level window it is considered a child window und doesn't get a taskbar entry per se. The parent window, on the other hand, also doesn't get a taskbar entry because you never set it visible: This code here works for me:

class MyWindowWidget : public QWidget
{
public:
    MyWindowWidget(QWidget *parent)
        : QWidget(parent, Qt::Dialog)
    {

    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QMainWindow window;

    MyWindowWidget widget(&window);
    widget.show();

    return app.exec();
}

No taskbar entry is ever shown, if this is want you intended.

Federalize answered 30/10, 2010 at 9:9 Comment(1)
I was facing this with one of App and after reading I realised problem was someone commit a object creation with this object. It was bug for me. I removed this and app worked perfectly i.e. taskbar entry comes back. Thanks you.Irksome
S
15

Just set Qt::SubWindow flag for widget.

Sophist answered 2/12, 2015 at 16:2 Comment(3)
This is definitely the easiest answer. Works for me with Qt5.Alesha
It's a good solution if Your window has no frame. If it does, then you wont have the default windows buttons (close, maximize, minimize).Drape
Where do I put this code? Can you give more detailed example?Orleanist
B
11

If you want to show/hide the widget without ever showing it at the taskbar your might check the windowflags of that widget. I'm not 100% sure, but I think I used Qt::Dialog | Qt::Tool and Qt::CustomizeWindowHint to achieve this, but my window wasn't fully decorated too. Another thing you might keep in mind if you play with that is the exit policy of your application. Closing/Hiding the last toplevel-window will normally exit your application, so maybe you need to call QApplication::setQuitOnLastWindowClosed(false) to prevent that...

Beghtol answered 29/10, 2010 at 22:17 Comment(4)
Qt::Tool is the relevant flag that prevents a taskbar entry.Pilcomayo
Nvm got it: this->setWindowFlags(Qt::tool);Orleanist
Heads up: On some WMs even children with parents are listed in the taskbar. As mentioned elsewhere setting the window type to Qt::Tool solves this but then some WMs don't allow maximizing of Tool windows. If you need that too you have to send the "_NET_WM_STATE_SKIP_TASKBAR" manually by getting the X11 connection from X11InfoDarryldarryn
@Darryldarryn : I was able to solve (or rather workaround) a similar problem thanks to your comment: https://mcmap.net/q/503851/-multi-window-qt-app-without-taskbar-entryMiletus
E
0

Python code to achive this:

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class MainWindow(QWidget):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent, Qt.Tool)

window = MainWindow()
window.show()
Eb answered 14/6, 2015 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.