Results 1 to 12 of 12

Thread: Which event when raising a window

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Which event when raising a window

    Hello,
    I have 2 main windows and I would like that each time one of them is raised by the user - by clicking on it - the other one be raised so as to always have all windows either visible or not, ie not hidden by another application (otherwise I have to raise each window individually).
    I was about to solve it by overloading the changeEvent() method but this method is not called when a window is raised by clicking on it. Any idea?

    Qt Code:
    1. void
    2. myClass::changeEvent(QEvent *event)
    3. {
    4. if (event->type() == QEvent::WindowStateChange) {
    5. if (this->windowState() & Qt::WindowActive) {
    6. printf("raised\n");
    7. }
    8. QWidget::changeEvent(event);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which event when raising a window

    Are you aware that clicking on a window doesn't have to bring it to front? This depends on the settings of the window manager. I don't think there is an event that handles what you want. You might try your luck with monitoring QApplication::focusChanged() signal however it is related to keyboard focus and not window visibility. You can also try with your current approach but so far you have been looking for a wrong event -- try checking for QEvent::ActivationChange instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Which event when raising a window

    Tried it but did not change anything, ie slot is not called.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which event when raising a window

    What slot do you mean?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Which event when raising a window

    According to your suggestion, I tried this:

    Qt Code:
    1. void
    2. myClass::changeEvent(QEvent *event)
    3. {
    4. if (event->type() == QEvent::ActivationChange) {
    5. if (this->windowState() & Qt::WindowActive) {
    6. printf("raised\n");
    7. }
    8. QWidget::changeEvent(event);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    and I expected that clicking on the upper band of the window, making it the active window, would have made this slot executed.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which event when raising a window

    It's not a slot.

    And the docs say:

    QEvent::ActivationChange 99 A widget's top-level window activation state has changed.
    Again, it has nothing to do with the window being raised or not. Activation is related to the keyboard focus.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Which event when raising a window

    You wrote:

    try checking for QEvent::ActivationChange instead
    so that is the reason I tried it!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which event when raising a window

    I have also written other things. Have you checked them?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Which event when raising a window

    Yes I understood that it is not possible to have all windows of an application raised together when one of them has been raised.
    I just investigated this route since you mentionned it.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Which event when raising a window

    I meant the focusChanged() signal.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Which event when raising a window

    I don't know about chaning focus wysota mentioned, but changeEvent works perfectly fine on w7 an ubuntu for me:

    Qt Code:
    1. // main
    2. int main(int argc, char *argv[])
    3. {
    4. QApplication a(argc, argv);
    5. MainWindow w;
    6. w.show();
    7.  
    8. MainWindow w2;
    9. w2.show();
    10.  
    11. QObject::connect( &w, SIGNAL( activated( QWidget* ) ), &w2, SLOT( activate( QWidget* ) ) );
    12. QObject::connect( &w2, SIGNAL( activated( QWidget* ) ), &w, SLOT( activate( QWidget* ) ) );
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // mainwindow.h
    2. #ifndef MAINWINDOW_H
    3. #define MAINWINDOW_H
    4.  
    5. #include <QtGui/QMainWindow>
    6.  
    7. class MainWindow : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. MainWindow( QWidget* parent = 0 );
    13.  
    14. protected:
    15. void changeEvent( QEvent* e );
    16.  
    17. public slots:
    18. void activate( QWidget* w );
    19.  
    20. signals:
    21. void activated( QWidget* w );
    22. };
    23.  
    24. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // mainwindow.cpp
    2. #include "mainwindow.h"
    3.  
    4. #include <QEvent>
    5.  
    6. MainWindow::MainWindow( QWidget* p )
    7. :
    8. {
    9. }
    10.  
    11. void MainWindow::changeEvent( QEvent* e )
    12. {
    13. if( e->type() == QEvent::ActivationChange
    14. && this->isActiveWindow() )
    15. {
    16. emit this->activated( this );
    17. }
    18. QMainWindow::changeEvent( e );
    19. }
    20.  
    21. void MainWindow::activate( QWidget* w )
    22. {
    23. this->raise();
    24. this->stackUnder( w );
    25. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Which event when raising a window

    Very good, thank you for this help,
    Ok with QT5 on Windows 8

Similar Threads

  1. Execute event in calling window
    By rdjenner in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2011, 15:28
  2. Memory raising forever in server thread application
    By ruben.rodrigues in forum Newbie
    Replies: 4
    Last Post: 1st July 2010, 21:54
  3. Raising main Window above floating DockWidgets
    By skimpax in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2009, 09:03
  4. Raising the MainWindow to active/focused state
    By bmahf in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2009, 21:15
  5. timerEvent is not raising
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 2nd September 2008, 22:07

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
  •  
Qt is a trademark of The Qt Company.