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 Should One Register Standard QActions in the Menu Bar to Perform the Appropriate Action?
Forum Updated to NodeBB v4.3 + New Features

How Should One Register Standard QActions in the Menu Bar to Perform the Appropriate Action?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 191 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.
  • J Offline
    J Offline
    johnzhou721
    wrote last edited by
    #1

    In the code example at https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/mainwindows/menus/mainwindow.cpp?h=6.9, the Edit > Cut etc. actions only print the action executed. How can I make it actually do what Edit > Cut would normally do in an app (cut text in the active widget)? ChatGPT suggests using the currently active widget and cut, but I'm not sure if it's the correct way.

    Sorry for being a Qt noob and asking all those trivial questions.

    jsulmJ 1 Reply Last reply
    0
    • J johnzhou721

      In the code example at https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/mainwindows/menus/mainwindow.cpp?h=6.9, the Edit > Cut etc. actions only print the action executed. How can I make it actually do what Edit > Cut would normally do in an app (cut text in the active widget)? ChatGPT suggests using the currently active widget and cut, but I'm not sure if it's the correct way.

      Sorry for being a Qt noob and asking all those trivial questions.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote last edited by
      #2

      @johnzhou721 Depends on what that widget is. If it is QTextEdit you simply call https://doc.qt.io/qt-6/qtextedit.html#cut

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      2
      • jsulmJ jsulm

        @johnzhou721 Depends on what that widget is. If it is QTextEdit you simply call https://doc.qt.io/qt-6/qtextedit.html#cut

        J Offline
        J Offline
        johnzhou721
        wrote last edited by
        #3

        @jsulm hmm… are those edit actions usually not present if there’s multiple line edits then? Like pressing Ctrl X should just cut in the active text field (or other widget) even if you do not have this QAction in the menu bar, so I want to add the item in Edit>Cut mapping to Ctrl X’s default behavior. Or is Edit > Cut inappropriate within a non editing document app? Thanks?

        jsulmJ Pl45m4P 2 Replies Last reply
        0
        • J johnzhou721

          @jsulm hmm… are those edit actions usually not present if there’s multiple line edits then? Like pressing Ctrl X should just cut in the active text field (or other widget) even if you do not have this QAction in the menu bar, so I want to add the item in Edit>Cut mapping to Ctrl X’s default behavior. Or is Edit > Cut inappropriate within a non editing document app? Thanks?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote last edited by
          #4

          @johnzhou721 said in How Should One Register Standard QActions in the Menu Bar to Perform the Appropriate Action?:

          Or is Edit > Cut inappropriate within a non editing document app?

          Not sure I understand. Usually the widget which has focus reacts to shortcuts. Can you explain what you mean with "non editing document app"?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • J johnzhou721

            @jsulm hmm… are those edit actions usually not present if there’s multiple line edits then? Like pressing Ctrl X should just cut in the active text field (or other widget) even if you do not have this QAction in the menu bar, so I want to add the item in Edit>Cut mapping to Ctrl X’s default behavior. Or is Edit > Cut inappropriate within a non editing document app? Thanks?

            Pl45m4P Online
            Pl45m4P Online
            Pl45m4
            wrote last edited by
            #5

            @johnzhou721 said in How Should One Register Standard QActions in the Menu Bar to Perform the Appropriate Action?:

            are those edit actions usually not present if there’s multiple line edits then?

            The shortcut is pretty much the same as pressing Ctrl + X.
            What else do you want to "cut"? If there is nothing to which you can apply "cut", nothing happens. Same as if you just press Ctrl + X without selecting some file/text.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            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