Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 268147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:39:23+00:00 2026-05-11T23:39:23+00:00

i have a QMainWindow. It has this parameters: this->setWindowFlags(Qt::Tool); this->setFocusPolicy(Qt::StrongFocus); this->setAttribute(Qt::WA_QuitOnClose,true); After showEvent calles

  • 0

i have a QMainWindow. It has this parameters:

this->setWindowFlags(Qt::Tool);
this->setFocusPolicy(Qt::StrongFocus);
this->setAttribute(Qt::WA_QuitOnClose,true);

After showEvent calles my window is shown but unactivated.
I tried to overload show function:

...    
QMainWindow::showEvent(event);
this->activateWindow();
...

But it doesn’t help me.

EDIT:
When i commented line

this->setWindowFlags(Qt::Tool);

everything worked fine, but i need in tool-flag.
Any ideas?

EDIT:

  • OS: Linux
  • Programming language: c++
  • Qt version: 4.5.1
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:39:24+00:00Added an answer on May 11, 2026 at 11:39 pm

    The Windows Manager Decides

    Before I start: As pointed out by elcuco and Javier, focus policy and other aspects of the windows layout (e.g. the title bar) belongs to a substantial extend to the respective windows manager, and Qt might have limited control. To see this, just look at a user interface that has a “focus follows mouse” policy. In these cases, the windows manager might ignore Qt’s focus request. For this reasons, the Qt documentation calls many of the respective flags “hints”. Consequently, some of the suggested solutions might or might not work for you.

    QApplication::setActiveWindow()

    This not withstanding, e.tadeu’s solution to use QApplication::setActiveWindow() works for me for both Windows and Ubuntu with Gnome. I tested it with the following code. Apologies that it is Python using PyQt (I use questions like these to learn a bit about PyQt). It should be fairly easy for you to read it and translate it into C++.

    import sys
    
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    
    class MainWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
            QtGui.QMainWindow.__init__(self)
    
            # main window
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('Test')
    
            # text editor
            self.textEdit = QtGui.QTextEdit()
            self.setCentralWidget(self.textEdit)
    
        def closeEvent(self, event):
            QtGui.QApplication.instance().quit()
    
    #main
    app = QtGui.QApplication(sys.argv)
    testWindow = MainWindow()
    testWindow.setWindowFlags(QtCore.Qt.Tool)
    testWindow.show()
    app.setActiveWindow(testWindow)
    app.exec_()
    

    Note that you have to add some handling of the close event of the testWindow, because the app does not exit automatically if you close a Qt::Tool window.

    The grabKeyboard() Hack

    If this does not work for you, the following hack might. I assume that you have a window in your application that is active. You can then use grabKeyboard() to redirect the input. The Qt::Tool window doesn’t get the focus, but receives the input. The following main code demonstrates it (the other code remains unchanged).

    #main
    app = QtGui.QApplication(sys.argv)
    testWindow = MainWindow()
    testWindow.setWindowFlags(QtCore.Qt.Tool)
    testWindow2 = MainWindow()   # second window which is active
    testWindow2.show()
    testWindow.show()
    testWindow.textEdit.grabKeyboard()
    app.exec_()
    

    Basically, while the window testWindow2 is the active one, all text entered shows up in testWindow.textEdit. It is not nice, I know…

    Creating Your Own Window

    You gain the most flexibility (and create the most work for yourself) by rolling out your own window layout. The idea is described in the following FAQ.

    Other “Solutions”

    You could directly call the respective window manager’s API function to get the desired result (clearly against the very reason for using Qt in the first place). You could also hack the Qt source code. For example, on Windows, Qt uses the ShowWindow() function with a SW_SHOWNOACTIVATE flag, to show a window with style WS_EX_TOOLWINDOW if you set the Qt::Tool flag. You could easily replace the SW_SHOWNOACTIVATE with whatever you want. Linux should be the same. Clearly also not recommended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QMainWindow which spawns a few wizards. The QMainWindow has a QFrame
I have a widget class subclass of QMainWindow, and it has a central widget(QWidget),
I have a Qt Designer Class called MainWindow which is a QMainWindow. This class
I have a QMainWindow that has a QWidget . The QWidget appears, and has
I have a PySide app which has an icon for the MainWindow (a QMainWindow
Summery : I have a custom UITabBarAutoRotateController which returns YES from shouldAutorotateToInterfaceOrientation. This has
I have a QMainWindow whose central widget has been set to a QGraphicsView viewing
I have a QMainWindow with two QTableViews on it. Each QTableView has its own
I would like to have a QMainWindow that can change it's look at runtime,
I have an inactive QMainWindow with a QTabWidget as CentralWidget which holds multiple QPlainTextEdits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.