Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]how to add combo box in trayicon menu?
Forum Updated to NodeBB v4.3 + New Features

[Solved]how to add combo box in trayicon menu?

Scheduled Pinned Locked Moved General and Desktop
20 Posts 3 Posters 11.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on 19 Oct 2011, 13:01 last edited by
    #6

    Volker, the question was not on how to add a menu, but how to put a combobox in that menu.

    @mady
    Volker is right about the documentation. Some quotes from the [[doc:QWidgetAction]] docs:
    quote if you want to implement an action that uses custom widgets for visualization in multiple containers then you have to subclass QWidgetAction.

    If a QWidgetAction is added for example to a QToolBar then QWidgetAction::createWidget() is called. Reimplementations of that function should create a new custom widget with the specified parent.[/quote]

    So: subclass QWidgetAction, reimplement createWidget() to return your combo box, create an instance of that subclassed action, and insert it in your menu.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 19 Oct 2011, 13:10 last edited by
      #7

      A combo box in a tray icon's menu - weird. I hope I never run into the situation of using such a user interface, sorry.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 19 Oct 2011, 13:12 last edited by
        #8

        Hey, I did not come up with that requirement, but I agree it's probably a bad idea. It is possible, though.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mady
          wrote on 19 Oct 2011, 17:57 last edited by
          #9

          Finally! You got what I am asking.
          Let me tell you the requirement. I wanted to add a list in tray menu which will be having some options, once user click on it a drop down list will be visible and it will contain those options. I thought combo box will help. Let me know if any other option is available to achieve the same.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 19 Oct 2011, 18:00 last edited by
            #10

            How about having checkable (possibly exclusive) menu options instead?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mady
              wrote on 19 Oct 2011, 18:06 last edited by
              #11

              Can I add radio button in tray menu? Because otu of those option user can select at a time only one.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 19 Oct 2011, 18:10 last edited by
                #12

                Yes, you can. See [[doc:QActionGroup]].

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mady
                  wrote on 21 Oct 2011, 10:41 last edited by
                  #13

                  Thanks Andre,
                  I have successfully able to create QActionGroup But how to add it into Qmenu that is not given any where in the link given by you. could you please help me to find out how to add QActionGroup into Qmenu?

                  Thanks in advance. :)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mady
                    wrote on 21 Oct 2011, 10:49 last edited by
                    #14

                    Hey,
                    I am able to add
                    but somehow leftAlignAct->setChecked(true); not working for me. I am not able to marked as checked any action in the group.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on 21 Oct 2011, 11:16 last edited by
                      #15

                      Adding should work like this:
                      @
                      myMenu->addActions(theActionGroup->actions());
                      @

                      On the not being able to mark an item as checked: could you show some code please? The code you show is from the example on the QActionGroup page.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mady
                        wrote on 21 Oct 2011, 11:32 last edited by
                        #16

                        I am working on a updater module which will be having a tray menu. Below is the code piece I am working on.
                        @
                        ........
                        Once1DayAction = new QAction(tr("Once in every day."), this);
                        connect(Once1DayAction, SIGNAL(triggered()), this, SLOT(UpdateGroupActs()));

                         Once7DayAction = new QAction(tr("Once in 7 days."), this);
                         connect(Once7DayAction, SIGNAL(triggered()), this, SLOT(UpdateGroupActs()));
                         Once7DayAction->setChecked(true);
                         
                            
                        alignmentGroup = new QActionGroup(this);
                        alignmentGroup->addAction(Once1DayAction); 
                        alignmentGroup->addAction(Once7DayAction); 
                        
                         // create tray icon menu
                         trayIconMenu = new QMenu(this);
                         trayIconMenu->addSeparator()->setText(tr("Updates"));  // Separater is visible but Text is not visible in the menu.   
                         trayIconMenu->addActions(alignmentGroup->actions());
                         trayIconMenu->addSeparator();
                         trayIconMenu->addAction(quitAction);
                         trayIcon = new QSystemTrayIcon(this);
                         trayIcon->setContextMenu(trayIconMenu);
                        

                        ........
                        @

                        Note: I tried to use "checkedAction" to see whether any thing is checked but it is returning NULL, seems nothing is set.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on 21 Oct 2011, 12:30 last edited by
                          #17

                          For some reason you must call setCheckable(true) on the actions to become checkable.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mady
                            wrote on 21 Oct 2011, 16:30 last edited by
                            #18

                            Hi Volker,
                            I tried both setChecked(true) and setCheckable(true) but none of them help. Not sure what is causing this problem. Please let me know if you have any clue.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on 21 Oct 2011, 21:52 last edited by
                              #19

                              I don't have any further ideas now. It did not work for me without calling setCheckable at first. After adding that, I could check the menu entries.

                              Which OS are you using?

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mady
                                wrote on 24 Oct 2011, 11:04 last edited by
                                #20

                                Thanks Every one thanks for your support and petience. It is working now. I had to use both in particular order.

                                1 Reply Last reply
                                0

                                15/20

                                21 Oct 2011, 11:16

                                • Login

                                • Login or register to search.
                                15 out of 20
                                • First post
                                  15/20
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved