How can i update QMenu and sub menu title text 's dynamically
-
i have QMenu that holds sub menu
i like to be able to update each menu title string dynamccly for example
i have this menu@[main menu ] Groups 2
[sub menu] group_X 3
[sub menu] group_Y 1@i like to be able to change only the numbers part of the string in each menu entry from my application
which approach should i peek ?Thanks
-
You can simply change the text property of the "QAction":http://doc.qt.nokia.com/latest/qaction.html#text-prop that the menu item represents.
-
say im using this method :
@menu -> setTitle (tr ("Number %1") .arg ("123"));@
how can i update dynamically the arg() method without rewriting the title over and over again
from outside . -
You can't. The "%1" is "lost" when you call QString::arg().
If you want to just update the "%1" part, you need to store the original QString somewhere, and use it again, with arg(), to create the updated menu title.
Alternatively, you could search the existing title for a number, and replace the number. -
but still in any of your methods i still have to rewrite the text , right ?
-
Yes but why is that a problem for you? Constructing a formatted string is of very minimal cost when compared to actually getting it rendered on-screen. I think you are trying to optimise away a problem that doesn't exist.