Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Minimizing Application to Tray
Forum Updated to NodeBB v4.3 + New Features

Minimizing Application to Tray

Scheduled Pinned Locked Moved General and Desktop
25 Posts 8 Posters 39.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AlicemirrorA Offline
    AlicemirrorA Offline
    Alicemirror
    wrote on last edited by
    #21

    I had the same problem with a windowless device... Decided for this solution :)

    Enrico Miglino (aka Alicemirror)
    Balearic Dynamics
    Islas Baleares, Ibiza (Spain)
    www.balearicdynamics.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      manuel.gysin
      wrote on last edited by
      #22

      To remove the button is no solution...
      Here is a dirty hack, but it works.

      @void MainWindow::changeEvent(QEvent *e)
      {
      if(isMinimized())
      {
      show(); // The hack
      slotToggleVisibility(); // Your tray icon code
      }
      }@

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ryan
        wrote on last edited by
        #23

        If anyone still has this issue, the solution is to call qApp->processEvents() before calling hide(), ie.

        @void ApplicationWindow::changeEvent(QEvent *event)
        {
        QWidget::changeEvent(event);
        if (event->type() == QEvent::WindowStateChange)
        {
        QWindowStateChangeEvent e = (QWindowStateChangeEvent)event;
        // make sure we only do this for minimize events
        if ((e->oldState() != Qt::WindowMinimized) && isMinimized())
        {
        qApp->processEvents();
        hide();
        event->ignore();
        }
        }
        }
        @

        The test for the old state is probably unnecessary, but can't hurt.

        If this doesn't help in your particular situation, try calling hide from a single-shot timer, so that the call is outside the minimize event handler:

        @void ApplicationWindow::changeEvent(QEvent *event)
        {
        QWidget::changeEvent(event);
        if (event->type() == QEvent::WindowStateChange)
        {
        QWindowStateChangeEvent e = (QWindowStateChangeEvent)event;
        // make sure we only do this for minimize events
        if ((e->oldState() != Qt::WindowMinimized) && isMinimized())
        {
        QTimer::singleShot(0, this, SLOT(hide()));
        event->ignore();
        }
        }
        }
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #24

          Hi Ryan,

          take care if you call qApp->processEvents(), as you reopen the event queue and it might happen that an event, that should be worked on after you finished is processed now. I don't say never do it, but do it with care and always remember, synchronous workflow is broken up here.

          Even a deleteLater might be processed so an object can be deleted, where you expect it not to be deleted.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ryan
            wrote on last edited by
            #25

            Yep, that's why I gave the second block of code (which I've just realised had the processEvents() call still in it - it wasn't meant to be there)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved