Qt Hide Taskbar Item
I have a custom QWidget and I simple don't want it to show up i开发者_JAVA百科n the taskbar. I have a QSystemTrayIcon for managing exiting/minimizing etc.
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.
Just set Qt::SubWindow flag for widget.
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...
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()
精彩评论