Results 1 to 9 of 9

Thread: About press esc key to exit fullscreen

  1. #1
    Join Date
    Oct 2012
    Posts
    35
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About press esc key to exit fullscreen

    Hi All,
    i have use designer to design a mainwidow which have a stackedWidget ,and the stackedWidget has several pages. i want to the page display fullscreen , and then pressed 'esc' key to exit fullscreen. but didn't respond. didn't print "esc". what's problem?



    void MainWindow::keyPressEvent(QKeyEvent *event)
    {
    if(event->key() == Qt::Key_Escape && !event->isAutoRepeat())
    {qDebug() << "esc";

    if(ui->stackedWidget->isFullScreen())
    {
    ui->stackedWidget->setWindowFlags(Qt::SubWindow);
    ui->stackedWidget->showNormal();
    }
    }
    }

    Please give me a advice!

    Thanks and Best Regards!

    ken


    Added after 1 4 minutes:


    i have set the focus, but didn't exit fullscreen also.
    Last edited by kenchan; 2nd December 2012 at 14:31.

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

    Default Re: About press esc key to exit fullscreen

    What is the focus policy of your MainWindow instance?
    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. The following user says thank you to wysota for this useful post:

    kenchan (25th December 2012)

  4. #3
    Join Date
    Oct 2012
    Posts
    35
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About press esc key to exit fullscreen

    Hi wysota,
    i have try to use all of options about focusPolicy such as StrongFocus,wheelFocus, tabFocus, clickfocus .but didn't respond also.

    please give me some advice to handle it.

    TKS.

    ken

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: About press esc key to exit fullscreen

    Hmm, what about using a QAction that has Escape as its short cut key sequence?

    You can then also add it to the menu, making it discoverable, to the context menu, etc.

    Cheers,
    _

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

    kenchan (25th December 2012)

  7. #5
    Join Date
    Oct 2012
    Posts
    35
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About press esc key to exit fullscreen

    Hi anda_skoa,

    your mean is add 'esc' QAction to the menu?

    i have try add eventfilter, cann't print 'esc', didn't use 'esc' key also. code as below:

    bool MainWindow::eventFilter(QObject *object, QEvent *event)
    {
    if (event->type() == QEvent::KeyPress)
    {
    QKeyEvent *k = (QKeyEvent *)event;

    if(k->key() == Qt::Key_Escape)
    {qDebug() << "esc";

    if(ui->stackedWidget->isFullScreen())
    {
    ui->stackedWidget->setWindowFlags(Qt::SubWindow);
    ui->stackedWidget->showNormal();
    }
    return true;
    }
    }
    else
    {
    return QWidget::eventFilter(object, event);
    }
    }

    please give some example if you can.

    TKS.

    ken

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

    Default Re: About press esc key to exit fullscreen

    Quote Originally Posted by kenchan View Post
    Hi wysota,
    i have try to use all of options about focusPolicy such as StrongFocus,wheelFocus, tabFocus, clickfocus .but didn't respond also.

    please give me some advice to handle it.
    For key events to be delivered to a widget, there is a requirement that the widget needs to have focus. For that two things need to happen:

    1. the widget needs to accept focus (done through a focus policy other than NoFocus)
    2. the widget needs to have focus currently (done e.g. by clicking on the widget)

    If you didn't fulfill step 2, then doing step 1 is not sufficient.
    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. The following user says thank you to wysota for this useful post:

    kenchan (25th December 2012)

  10. #7
    Join Date
    Oct 2012
    Posts
    35
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About press esc key to exit fullscreen

    Hi wysota,

    the step 2 happened when the programming running? if yes, i have clicked the widget before press 'esc' key.

    and the step 1 I have seted StrongFocus . pls see as below:

    ui->stackedWidget->setFocusPolicy(Qt::StrongFocus);

    TKS.

    ken


    Added after 1 51 minutes:


    Hi All,

    i have completed used eventfilter.

    thank you very much for giving me advice!

    ken
    Last edited by kenchan; 3rd December 2012 at 03:11. Reason: updated contents

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

    Default Re: About press esc key to exit fullscreen

    Quote Originally Posted by kenchan View Post
    and the step 1 I have seted StrongFocus . pls see as below:

    ui->stackedWidget->setFocusPolicy(Qt::StrongFocus);
    That sets focus on the stacked widget, not on the main window.
    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.


  12. The following user says thank you to wysota for this useful post:

    kenchan (25th December 2012)

  13. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: About press esc key to exit fullscreen

    Quote Originally Posted by kenchan View Post
    Hi anda_skoa,

    your mean is add 'esc' QAction to the menu?
    Yes, a QAction with the escape key being its shortcut QKeySequence

    Quote Originally Posted by kenchan View Post
    i have try add eventfilter, cann't print 'esc', didn't use 'esc' key also. code as below:
    That is another option, make sure to install it on the QApplication instance.

    Cheers,
    _

  14. The following user says thank you to anda_skoa for this useful post:

    kenchan (25th December 2012)

Similar Threads

  1. cannot exit from fullscreen
    By lazycoder in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2011, 06:38
  2. How exit FullScreen from videoWidget ? thanks for help
    By Mr.Simple in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2011, 06:26
  3. Fullscreen in qml
    By vinayaka in forum Newbie
    Replies: 2
    Last Post: 3rd October 2011, 07:05
  4. fullscreen opengl
    By k2 in forum Qt Programming
    Replies: 4
    Last Post: 30th April 2009, 18:15
  5. Fullscreen
    By dragor in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2006, 21:23

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.