×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    How to hightlight a menu item in Qt on Fremantle?

    Hi all,

    I have a Menu with 4 menu items (QAction* objects) and I want to always keep highlighted a particular menu item.
    For eg:
    If I have a menu item "Settings" and if a widget opens when I select "Settings", the menu should be displayed with "Settings" highlighted.

    I tried to apply QStyleSheet on QMenu, but it would not help to keep a menu item permanently selected.
    I also tried QWidgetAction* instead of QAction* and tried adding QLabel* to QWidgetAction. But it didn't work
    in Fremantle.

    It would be great if any one of you can help me with this.

    Thanks in advance

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by boppana View Post
    If I have a menu item "Settings" and if a widget opens when I select "Settings", the menu should be displayed with "Settings" highlighted.
    Which widget? How can widget open? Normally, if you select item in menu, menu closes, then how menu item could be displayed highlighted?

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post
    Which widget? How can widget open? Normally, if you select item in menu, menu closes, then how menu item could be displayed highlighted?

    Yes, when I select the menu item, menu closes. Now after I click on the menu again, it should highlight my last selected menu item.

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by boppana View Post
    Yes, when I select the menu item, menu closes. Now after I click on the menu again, it should highlight my last selected menu item.
    You can make it checked:
    http://doc.trolltech.com/4.6/qaction.html#checked-prop

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post

    I tried it, but it doesn't highlight the menu item.
    May be this code would help you to understand my problem better.

    QAction* accountsAction = new QAction(tr("Accounts"),this);
    QAction* meAction = new QAction(tr("Me"),this);
    QAction* settingsAction = new QAction(tr("Settings"),this);
    QAction* friendsAction = new QAction(tr("Friends"),this);

    I would like to make friendsAction highlighted to specify that it is the default menu when the application launches.
    This statement,

    friendsAction->setChecked(true);

    would not highlight the menu item.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?


  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post
    I have gone through this thread earlier and tried replacing QAction with QWidgetAction, but QWidgetAction does not work on device (N900).

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by boppana View Post
    I have gone through this thread earlier and tried replacing QAction with QWidgetAction, but QWidgetAction does not work on device (N900).
    QWidgetAction were disabled in Maemo due to specific menu implementation. However, you still can go with QAction::setCheckable, QAction::setChecked and styling QMenu::item:checked.

  9. #9
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post
    QWidgetAction were disabled in Maemo due to specific menu implementation. However, you still can go with QAction::setCheckable, QAction::setChecked and styling QMenu::item:checked.
    Hi,

    Can you please look at the below code and let me know if it is correct.

    QAction* friendsAction = new QAction("Friends", this);
    friendsAction->setChecked(true);
    friendsAction->setCheckable(true);

    QMenu* fileMenu = menuBar()->addMenu("");
    fileMenu->addAction(friendsAction);
    QString menuStyle("QMenu::item:checked { background-color: #654321; }");
    fileMenu->setStyleSheet(menuStyle);

    This piece of code adds a check box to the friendsAction, when the application is executed outside scratch box (in QtCreator).
    But it doesn't show any styling on the menu when I run the same in Scratchbox.

    Rgds
    boppana

  10. #10
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?


  11. #11
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post
    hi,

    I guess its a problem with Xephyr. I just tried my code on the device and its working.
    Sorry for the inconvenience and thanks a lot for the solution.

    Regards
    bopana

  12. #12
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by boppana View Post
    I guess its a problem with Xephyr. I just tried my code on the device and its working.
    Sorry for the inconvenience and thanks a lot for the solution.
    The code you've posted contains a bug and this is not Xephyr problem.

  13. #13
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post
    The code you've posted contains a bug and this is not Xephyr problem.
    Can you please tell me where the bug is?

  14. #14
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by boppana View Post
    Can you please tell me where the bug is?
    You will learn something, if you find it yourself.

  15. #15
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: How to hightlight a menu item in Qt on Fremantle?

    Quote Originally Posted by divanov View Post
    You will learn something, if you find it yourself.
    True..
    I got it now

Similar Threads

  1. making menu item in nokia menu
    By Arunesh in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-11-04, 10:56
  2. deleting menu item
    By sumit.rathi in forum Symbian
    Replies: 1
    Last Post: 2008-10-16, 13:51
  3. dynemic menu
    By pankaj gupta55 in forum Symbian
    Replies: 1
    Last Post: 2008-09-20, 11:33
  4. Replies: 3
    Last Post: 2006-11-23, 17:24
  5. How to add a menu item in the Options menu of a Nokia 7650 ?
    By nmittal in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-08-07, 08:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×