How Should One Register Standard QActions in the Menu Bar to Perform the Appropriate Action?
-
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.
-
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.
@johnzhou721 Depends on what that widget is. If it is QTextEdit you simply call https://doc.qt.io/qt-6/qtextedit.html#cut
-
@johnzhou721 Depends on what that widget is. If it is QTextEdit you simply call https://doc.qt.io/qt-6/qtextedit.html#cut
@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?
-
@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?
@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"?
-
@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?
@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 pressCtrl + X
without selecting some file/text.