PDA

View Full Version : Hide QMainWindow without removing taskbar icon?



bigchiller
14th March 2009, 17:02
Hey Guys,

I am wondering if it is possible to hide a QMainWindow object but keep its taskbar icon?

I am implementing a new view with minimal screen footprint. When the user enters this new view I would like to hide the main client and render a new child Widget to represent a toolbar for the user. As soon as I hide my QMainWindow, the taskbar icon is removed, even if I have child widget visible.

Is there any way around this?

ComaWhite
14th March 2009, 17:04
Here is what I have to do it for me



void
MainWindow::closeEvent(QCloseEvent *event) {
if (Settings::enableSystemTray()) {
if (Settings::minimizeToTrayOnClose()) {
hide();
event->ignore();
}
} else {
KXmlGuiWindow::closeEvent(event);
}
}


Just replace KXmlGuiWindow with QMainWindow since KXmlGuiWindow is KDE code

bigchiller
14th March 2009, 17:28
Here is what I have to do it for me



void
MainWindow::closeEvent(QCloseEvent *event) {
if (Settings::enableSystemTray()) {
if (Settings::minimizeToTrayOnClose()) {
hide();
event->ignore();
}
} else {
KXmlGuiWindow::closeEvent(event);
}
}


Just replace KXmlGuiWindow with QMainWindow since KXmlGuiWindow is KDE code

I just tried this and it doesn't work. Maybe you misunderstood what I am trying to do. I don't think I was clear enough :(

here is some code:


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

// create and show main window
TestWindow* mainWindow = new TestWindow();
mainWindow->show();

// create and show child window
QMainWindow* childWindow = new QMainWindow(mainWindow);
childWindow->show();

/// now we have 2 windows on screen and 1 icon on taskbar

// hide main window.
mainWindow->hide() ;

// now I have childWindow on screen but no icons on taskbar.
// I would like to the taskbar icon to remain and its functions (maximize, minimize, close, etc) to control the child window.

return a.exec();
}


In my TestWindow class i overrode the closeEvent as you had it and It didn't work for me. In fact, the closeEvent isnt fired after a hide()

aamer4yu
15th March 2009, 05:48
You could try calling mainWindow->showMinimized();

If that doesnt work, you can try this -
Set the opacity of the main window to 0. The window would be there, not visible. But how you choose to make it opaque again might be tricky :D

bigchiller
15th March 2009, 16:42
You could try calling mainWindow->showMinimized();

If that doesnt work, you can try this -
Set the opacity of the main window to 0. The window would be there, not visible. But how you choose to make it opaque again might be tricky :D

If i use showMinimized() and then click the taskbar icon for the window, it will still show options such as maximize which will maximize both the child and parent windows.

The only way I'm aware of overriding the maximize window operation is to use windows specific or x11 specific code. Does anyone know of a better way to override the maximize operation so that if the user attempts to maximize from the taskbar they won't be able to?

wysota
15th March 2009, 22:54
What's the point of having a taskbar entry if you can't do anything with it? Maybe you should just show the taskbar entry for the child you show instead of the main window?