Questions about making a QMenu
-
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? -
Does QToolButton provide a possible solution?
-
I will check it out, but what about question 3?
how do i get the position of the action that was pressed? -
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)
@ -
Q4) How to select an action, like this?
!http://i.imgur.com/Xdk5a8W.png(1)!
at the screenshot, the action
is checkedsetCheckable(true);
setChecked(true);text is bold
QFont bold;
bold.setBold(true);setFont(bold);
and selected
how? -
I edited my question/answers.
But questions 3 and 4 are unaswered and i have no idea on what to do... -
Why do you need to know the position of the action?
-
[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?