Results 1 to 3 of 3

Thread: To set keyboard focus on QMenu item pragrammatically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Exclamation To set keyboard focus on QMenu item pragrammatically

    i am developing a Qt based GUI software.Whenever this software starts up, focus is set to the mainwindow.And there is no way to access the menu bar unless you are setting the focus to the menu by clicking the mouse on it.But my software requirements restricted the use of the mouse(only keyboard will be used as the medium of interaction with users);plz advise how
    can i do that

    Here is my existing code.

    main.cpp


    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QMenuBar>
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QMainWindow *window = new QMainWindow();
    9.  
    10.  
    11. window->setWindowTitle(QString::fromUtf8("Test:QMenu"));
    12. window->resize(336, 227);
    13.  
    14.  
    15.  
    16. QAction *newAct = new QAction("&New",window);
    17. QAction *openAct = new QAction("&Open",window);
    18. QAction *saveAct = new QAction("&Save",window);
    19.  
    20. QMenu *fileMenu;
    21.  
    22. fileMenu = window->menuBar()->addMenu("&File");
    23. fileMenu->addAction(newAct);
    24. fileMenu->addAction(openAct);
    25. fileMenu->addAction(saveAct);
    26.  
    27.  
    28. window->show();
    29.  
    30. fileMenu->popup(QPoint(10,10));
    31.  
    32.  
    33.  
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 17th April 2013 at 12:03. Reason: Merge, missing code tags

Similar Threads

  1. Get keyboard focus on mouse over (hover to activate)
    By mortoray in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2011, 19:23
  2. Replies: 3
    Last Post: 22nd August 2011, 08:47
  3. Tool Button keyboard focus?
    By ts230 in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2010, 05:31
  4. keyboard focus
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2008, 15:40
  5. Replies: 2
    Last Post: 24th July 2006, 18:36

Tags for this Thread

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.