Results 1 to 6 of 6

Thread: Problem hiding main window on minimize

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem hiding main window on minimize

    I have read some previous posts on this, and some other articles on the subject... but am still having a problem. I am using 4.2.2 and don't know if 4.3.1 would fix it.

    Essentially I have a window that derives from QMainWindow and is using a QSystemTrayIcon component. I am over-riding eventClose(...) to hide my window and show my systray icon. Double clicking the icon raise()es and activateWindows()s my main window. The problem is on minimize...

    I tried over-riding event(...) and changeEvent(...). I hide my windows, show my icon and boom... something retarded happens. My windows is inactivated and sitting on my task bar. Overridding event(..) and calling hide() seems to work when I walk through it, but when it returns it adds my app back on to the task bar. I have tried to ignore the event and everything. Sounds like a bug in 4.2.2 to me, but I wanted to see what you guys think.

    Here is some example code:

    Qt Code:
    1. // tried a similar approach with event(QEvent*).. ignoring the event, etc.
    2. void CINQtMainWindow::changeEvent(QEvent * e )
    3. {
    4. if (e->type() == QEvent::WindowStateChange)
    5. {
    6. if (isMinimized() == true)
    7. {
    8. hide();
    9. m_oSysTray.ShowIcon();
    10.  
    11. return;
    12. }
    13. }
    14.  
    15. QMainWindow::changeEvent( e );
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CINQtMainWindow::slotSysTrayDblClk()
    2. {
    3. m_oSysTray.HideIcon();
    4.  
    5. raise();
    6. activateWindow();
    7.  
    8. show();
    9. }
    To copy to clipboard, switch view to plain text mode 

    When slotSysTrayDblClk() gets called after minimizing... my app does not get raised, but sits in the task bar. When the app is minimized, you can click it on the task bar and it will show an inactivated window (essentially a black box).

    4.2.2 bug? Fixed in 4.3.x?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem hiding main window on minimize

    But this worked in 4.2.2 also, as far as I remember...
    Have you tried this:
    Qt Code:
    1. void Window::setVisible(bool visible)
    2. {
    3. minimizeAction->setEnabled(visible);
    4. maximizeAction->setEnabled(!isMaximized());
    5. restoreAction->setEnabled(isMaximized() || !visible);
    6. QWidget::setVisible(visible);
    7. }
    8.  
    9. void Window::closeEvent(QCloseEvent *event)
    10. {
    11. if (trayIcon->isVisible()) {
    12. QMessageBox::information(this, tr("Systray"),
    13. tr("The program will keep running in the "
    14. "system tray. To terminate the program, "
    15. "choose <b>Quit</b> in the context menu "
    16. "of the system tray entry."));
    17. hide();
    18. event->ignore();
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 
    It is from the examples( of 4.3.0)
    Should do the same for a state change event.

  3. #3
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem hiding main window on minimize

    My close event works perfectly. There is something about minimize that appears to force the application to appear on the task bar. I will see if something in your setVisible() method will get it to work correctly, but I have my doubts.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem hiding main window on minimize

    Does isMinimized() returns true in your change event?
    I am not sure if the window is yet minimized when it gets this event. It shouldn't be, since you have the option to ignore it.

    regards

  5. #5
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem hiding main window on minimize

    event() seems to get it before it minimizes, changeEvent() seems to get it after it minimizes. Either way, ignoring the event still makes it appear in the task bar after returning from those methods. That is why I think it is a bug... I just wanted to see if you guys had some obvious magical answer before I bothered the trolls.

  6. #6
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem hiding main window on minimize

    I contacted Trolltech and they gave me this gem:

    Qt Code:
    1. void CINQtMainWindow::changeEvent(QEvent * e )
    2. {
    3. if (e->type() == QEvent::WindowStateChange)
    4. {
    5. if (isMinimized() == true)
    6. {
    7. QTimer::singleShot(0, this, SLOT(hide()));
    8. m_oSysTray.ShowIcon();
    9. e->ignore();
    10.  
    11. return;
    12. }
    13. }
    14.  
    15. QMainWindow::changeEvent( e );
    16. }
    To copy to clipboard, switch view to plain text mode 

    QTimer::singleShot(0, this, SLOT(hide())); instead of hide()

  7. The following 3 users say thank you to bpetty for this useful post:

    araglin (8th May 2009), Memnoch (28th January 2009), tpf80 (17th January 2009)

Similar Threads

  1. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 16:40
  2. New to QT, problem displaying main window...
    By McCall in forum Qt Programming
    Replies: 4
    Last Post: 15th June 2007, 15:27
  3. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 09:41
  4. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 09:35
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 11:21

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.