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. Add actions from QTextEdit to Edit Menu
Forum Updated to NodeBB v4.3 + New Features

Add actions from QTextEdit to Edit Menu

Scheduled Pinned Locked Moved Solved General and Desktop
qtexteditqt5.5
10 Posts 3 Posters 3.6k Views 3 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.
  • C Offline
    C Offline
    ChajusSaib
    wrote on last edited by ChajusSaib
    #1

    Hello lads, so I need a way to add the context menu actions from QTextEdit to the Edit menu. I could re-implement these but there would be no point as their behaviour is exactly what I would like. Here is the context menu I am talking about

    Another question is how do I add text beside this tick that shows and hides the Toolbar menu.

    Thank you

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      if you want to extent the context menu you can follow the guideline provided here.

      About the second question I think (sorry I'm on Mac and the menus are integrated in the system one) you should set the Menu objectName

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      C 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Nothing forbids you to have several actions calling the same slot.

        How do you create that tick enabled menu ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • M mcosta

          Hi,

          if you want to extent the context menu you can follow the guideline provided here.

          About the second question I think (sorry I'm on Mac and the menus are integrated in the system one) you should set the Menu objectName

          C Offline
          C Offline
          ChajusSaib
          wrote on last edited by
          #4

          @mcosta said:

          Hi,

          if you want to extent the context menu you can follow the guideline provided here.

          About the second question I think (sorry I'm on Mac and the menus are integrated in the system one) you should set the Menu objectName

          @SGaist said:

          Hi,

          Nothing forbids you to have several actions calling the same slot.

          How do you create that tick enabled menu ?

          The first issue is solved just by adding more slots and connecting them to the QTextEdit ones except Delete as it seems there is no slot for that. How would I implement the Delete action?

          I would like to correct my self, the menu with the tick hides and shows the Toolbar and not the Menu. I did not create this menu. Setting the objectName does not add text beside the tick.

          Thank ye both for your help, appreciate it!

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mcosta
            wrote on last edited by
            #5

            @ChajusSaib said:

            I would like to correct my self, the menu with the tick hides and shows the Toolbar and not the Menu. I did not create this menu. Setting the objectName does not add text beside the tick.

            You have to set the Toolbar windowTitle
            Imgur
            Imgur

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            C 1 Reply Last reply
            1
            • M mcosta

              @ChajusSaib said:

              I would like to correct my self, the menu with the tick hides and shows the Toolbar and not the Menu. I did not create this menu. Setting the objectName does not add text beside the tick.

              You have to set the Toolbar windowTitle
              Imgur
              Imgur

              C Offline
              C Offline
              ChajusSaib
              wrote on last edited by
              #6

              @mcosta I feel so stupid now (facepalm). Thank you

              Anyone got an idea for implementing the Delete action? Thanks

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mcosta
                wrote on last edited by
                #7

                Delete --> clear() ??

                You could use the QTextCursor API

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                C 1 Reply Last reply
                1
                • M mcosta

                  Delete --> clear() ??

                  You could use the QTextCursor API

                  C Offline
                  C Offline
                  ChajusSaib
                  wrote on last edited by
                  #8

                  @mcosta No delete only deletes/clears the selection, it does not remove everything. I will take a look at the QTextCursor API. Thank you once again mate!

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mcosta
                    wrote on last edited by
                    #9

                    Hi,

                    I think QTextCursor::removeSelectedText() is what you're looking for

                    void MyEditor::slotDelete()
                    {
                        m_textEdit->textCursor().removeSelectedText();
                    }
                    

                    should do the job

                    Once your problem is solved don't forget to:

                    • Mark the thread as SOLVED using the Topic Tool menu
                    • Vote up the answer(s) that helped you to solve the issue

                    You can embed images using (http://imgur.com/) or (http://postimage.org/)

                    C 1 Reply Last reply
                    1
                    • M mcosta

                      Hi,

                      I think QTextCursor::removeSelectedText() is what you're looking for

                      void MyEditor::slotDelete()
                      {
                          m_textEdit->textCursor().removeSelectedText();
                      }
                      

                      should do the job

                      C Offline
                      C Offline
                      ChajusSaib
                      wrote on last edited by
                      #10

                      @mcosta You legend, thank you!

                      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