Results 1 to 6 of 6

Thread: Hide QMainWindow without removing taskbar icon?

  1. #1

    Default Hide QMainWindow without removing taskbar icon?

    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?

  2. #2
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Hide QMainWindow without removing taskbar icon?

    Here is what I have to do it for me

    Qt Code:
    1. void
    2. MainWindow::closeEvent(QCloseEvent *event) {
    3. if (Settings::enableSystemTray()) {
    4. if (Settings::minimizeToTrayOnClose()) {
    5. hide();
    6. event->ignore();
    7. }
    8. } else {
    9. KXmlGuiWindow::closeEvent(event);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Just replace KXmlGuiWindow with QMainWindow since KXmlGuiWindow is KDE code
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  3. #3

    Default Re: Hide QMainWindow without removing taskbar icon?

    Quote Originally Posted by ComaWhite View Post
    Here is what I have to do it for me

    Qt Code:
    1. void
    2. MainWindow::closeEvent(QCloseEvent *event) {
    3. if (Settings::enableSystemTray()) {
    4. if (Settings::minimizeToTrayOnClose()) {
    5. hide();
    6. event->ignore();
    7. }
    8. } else {
    9. KXmlGuiWindow::closeEvent(event);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. // create and show main window
    6. TestWindow* mainWindow = new TestWindow();
    7. mainWindow->show();
    8.  
    9. // create and show child window
    10. QMainWindow* childWindow = new QMainWindow(mainWindow);
    11. childWindow->show();
    12.  
    13. /// now we have 2 windows on screen and 1 icon on taskbar
    14.  
    15. // hide main window.
    16. mainWindow->hide() ;
    17.  
    18. // now I have childWindow on screen but no icons on taskbar.
    19. // I would like to the taskbar icon to remain and its functions (maximize, minimize, close, etc) to control the child window.
    20.  
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    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()

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide QMainWindow without removing taskbar icon?

    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

  5. #5

    Default Re: Hide QMainWindow without removing taskbar icon?

    Quote Originally Posted by aamer4yu View Post
    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
    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Hide QMainWindow without removing taskbar icon?

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. hide from taskbar but show to ALT-TAB
    By musikit in forum Qt Programming
    Replies: 0
    Last Post: 15th August 2008, 16:14
  2. Hide taskbar button
    By JeanC in forum Qt Programming
    Replies: 9
    Last Post: 12th March 2008, 09:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.