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. Questions about making a QMenu

Questions about making a QMenu

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.9k Views
  • 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    What i want to do is to have a button, and when pressed, show a QMenu right below it. The actions
    will be some kind of history of recent files.

    Q1) Positioning the QMenu below the button
    Answer:
    @ui->button->setMenu(Menu)@
    Q2) So you press the button one time and the Menu shows up, pressing the button again must hide and not show the menu again.
    Answer: Again
    @ui->button->setMenu(Menu);@
    with the help of aboutToShow signal to update the Menu everytime it is to been shown.

    Q3) How to i take the position of an action at the QMenu?
    One solution is after the addAction(text) to have a SetData(i) and then just take the position with ->Data() but is there is a better way on it?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #2

      Does QToolButton provide a possible solution?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon
        wrote on last edited by
        #3

        I will check it out, but what about question 3?
        how do i get the position of the action that was pressed?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Seamus Boyle
          wrote on last edited by
          #4

          You can add a menu to a push button with:
          @void QPushButton::setMenu(QMenu * menu)@

          You can add a menu to a tool button and set its popup mode with:
          @
          void QToolButton::setMenu(QMenu * menu)
          void QToolButton::setPopupMode(ToolButtonPopupMode mode)
          @

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            Q4) How to select an action, like this?
            !http://i.imgur.com/Xdk5a8W.png(1)!
            at the screenshot, the action
            is checked

            setCheckable(true);
            setChecked(true);

            text is bold
            QFont bold;
            bold.setBold(true);

            setFont(bold);

            and selected
            how?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Leon
              wrote on last edited by
              #6

              I edited my question/answers.
              But questions 3 and 4 are unaswered and i have no idea on what to do...

              1 Reply Last reply
              0
              • S Offline
                S Offline
                ScottR
                wrote on last edited by
                #7

                Why do you need to know the position of the action?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  Leon
                  wrote on last edited by
                  #8

                  [quote author="ScottR" date="1393508882"]Why do you need to know the position of the action?[/quote]

                  it is simple, as said it is some kind of file explorer that has a history of paths and if you click at an action it goes you there.

                  But there are also back/forward buttons that need to know the position of the current path at the history Menu.

                  So you say there is no particular way on doing it, and setData should be the solution?

                  1 Reply Last reply
                  0

                  • Login

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