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. How can i update QMenu and sub menu title text 's dynamically
Forum Updated to NodeBB v4.3 + New Features

How can i update QMenu and sub menu title text 's dynamically

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.9k 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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      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.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

        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 .

        1 Reply Last reply
        0
        • L Offline
          L Offline
          ludde
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #5

            but still in any of your methods i still have to rewrite the text , right ?

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #6

              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.

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              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