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. Mainscreen Active Window State Trouble
Qt 6.11 is out! See what's new in the release blog

Mainscreen Active Window State Trouble

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 857 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.
  • C Offline
    C Offline
    Crag_Hack
    wrote on last edited by
    #1

    Hi I am having a small problem with my main window class derived from QMainWindow. I am trying to test if the window is active with keyboard focus using the following code. I want to show notification area messages when it's not active. The only problem is the code fires even when the mainwindow is active. Any ideas?

    if (!(windowState().testFlag(Qt::WindowActive)))
            if (notifications)
            {
                QIcon icon(":/images/icons/rep.ico");
                trayIcon->showMessage("Rep", message, icon, 500);
            }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @Crag_Hack said in Mainscreen Active Window State Trouble:

      Qt::WindowActive

      You cant check if QWindow::isActive() returns true? Another Solution i found would be

      bool MainWindow::event(QEvent * e) // overloading event(QEvent*) method of QMainWindow 
      {
          switch(e->type())
          {
              // ...
      
              case QEvent::WindowActivate :
                  // gained focus
                  break ;
      
              case QEvent::WindowDeactivate :
                  // lost focus
                  break ;
              // ...
          } ;
          return QMainWindow::event(e) ;
      }
      
      1 Reply Last reply
      2
      • C Offline
        C Offline
        Crag_Hack
        wrote on last edited by
        #3

        Thanks Fuel. IsActiveWindow() didn't work so I just used ishidden() and isminimized() which isn't perfect but good enough for now. I'll try the event overload when I have time.

        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