Results 1 to 10 of 10

Thread: Qt::Tool

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt::Tool

    As soon as I setWindowFlags(Qt::Tool) strange things start happening.

    The window does not get keyboard focus on startup.
    When closing with the X in the upper right corder, the process is not terminated (but it does when called via slot aApp quit().
    Also closeEvent(QCloseEvent *event) does not get called.

    It does this with an otherwise empty test project.

    There's a Qt example program windowflags, but this one gets terminated when choosing a Tool window.
    What could this be?

    P.s. I'm using qdevelop, great tool, and the project is in debug mode.

    [edit] I think a window with Qt::Tool flag cannot be a normal mainwindow. It is a qwidget in the windowflags example, not a qmainwindow.
    Last edited by JeanC; 5th February 2008 at 19:32.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::Tool

    Could you provide a minimal compilable example we could try ourselves?
    J-P Nurmi

  3. #3
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qt::Tool

    When reading your post, it looks like you are trying to put a QT::tool flag on a widget inside a QMainWindow.

    If that is the case, it is correct that strange things will happen, as it tries making a tool window out of your widget inside a QMainWindow. Try using the QT::tool flag on either a dialog or the mainwindow directly if you are trying to have a tooltip-like-window

  4. #4
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Tool

    @jpn
    Sorry I hadn't noticed your question untill now.
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindowimpl.h"
    3. //
    4. int main(int argc, char ** argv)
    5. {
    6. QApplication app( argc, argv );
    7. MainWindowImpl win;
    8. win.show();
    9. app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "mainwindowimpl.h"
    2. //
    3. MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
    4. : QMainWindow(parent, f)
    5. {
    6. setupUi(this);
    7. setWindowFlags(Qt::Tool);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef MAINWINDOWIMPL_H
    2. #define MAINWINDOWIMPL_H
    3. //
    4. #include <QMainWindow>
    5. #include "ui_mainwindow.h"
    6. //
    7. class MainWindowImpl : public QMainWindow, public Ui::MainWindow
    8. {
    9. Q_OBJECT
    10. public:
    11. MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    12. private slots:
    13. };
    14. #endif
    To copy to clipboard, switch view to plain text mode 

    @luf
    Well no, it's on a main window as you can see.
    The example 'windowsflags' uses a widget to set Qt::Tool and is working,

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::Tool

    Alright, I found the reason. QWidget::create() clears the Qt::WA_QuitOnClose attribute for anything but Qt::Window, Qt::Widget or Qt::Dialog. The workaround is to call for example QWidget::show() first, and set the attribute by hand afterwards:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QMainWindow win(0, Qt::Tool);
    7. win.show(); // must be called before setting Qt::WA_QuitOnClose
    8. win.setAttribute(Qt::WA_QuitOnClose);
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    JeanC (8th February 2008)

  7. #6
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Tool

    Thanks jpn,

    There is another issue. That window does not get focus at startup. Calling setFocus() in main or in the constructor does not help.

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::Tool

    Looks like you have to explicitly activate the window:
    Qt Code:
    1. win.activateWindow();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    JeanC (8th February 2008)

  10. #8
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Tool

    Grr, that won't set focus jpn. Neither in main nor constructor.


    Quote Originally Posted by jpn View Post
    Looks like you have to explicitly activate the window:
    Qt Code:
    1. win.activateWindow();
    To copy to clipboard, switch view to plain text mode 

  11. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::Tool

    Alright, this seems to be something WM specific then. While it worked on Windows the window stays inactive on X11. Try this:

    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. class MainWindow : public QMainWindow
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. MainWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0)
    10. : QMainWindow(parent, flags)
    11. {
    12. setCentralWidget(new QTextEdit(this));
    13. }
    14.  
    15. public slots:
    16. void activateWindow()
    17. {
    18. QMainWindow::activateWindow();
    19. }
    20. };
    21.  
    22. int main(int argc, char* argv[])
    23. {
    24. QApplication app(argc, argv);
    25. MainWindow win(0, Qt::Tool);
    26. win.show(); // must be called before setting Qt::WA_QuitOnClose
    27. win.setAttribute(Qt::WA_QuitOnClose);
    28. QTimer::singleShot(0, &win, SLOT(activateWindow()));
    29. return app.exec();
    30. }
    31.  
    32. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    PS. Could you update your profile to indicate used platforms, please?
    J-P Nurmi

  12. #10
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Tool

    Works! Thanks.

    Quote Originally Posted by jpn View Post
    Alright, this seems to be something WM specific then. While it worked on Windows the window stays inactive on X11. Try this:
    Done. Only ubuntu so far, on win I used c++ builder.

    PS. Could you update your profile to indicate used platforms, please?

Similar Threads

  1. Replies: 5
    Last Post: 4th August 2006, 23:44

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.