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 to copy highlighted text from QTextEdit, PyQt6
Forum Updated to NodeBB v4.3 + New Features

How to copy highlighted text from QTextEdit, PyQt6

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.6k Views
  • 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.
  • W Offline
    W Offline
    WorldTeacher
    wrote on last edited by
    #1

    I have an application designed in QtDesigner and in it, there's a QTextEdit in which I put data from a query. I want to allow the user to select and copy text using the shortcut ctrl+c, but I can't seem to get it to work. The quick search I've done only shows examples on how to do it using buttons.

    Can I enable the copying using the shortcut? And if yes, how would I do it?

    Any answer is appreciated.

    JonBJ jsulmJ 2 Replies Last reply
    0
    • W WorldTeacher

      I have an application designed in QtDesigner and in it, there's a QTextEdit in which I put data from a query. I want to allow the user to select and copy text using the shortcut ctrl+c, but I can't seem to get it to work. The quick search I've done only shows examples on how to do it using buttons.

      Can I enable the copying using the shortcut? And if yes, how would I do it?

      Any answer is appreciated.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @WorldTeacher
      It should be working as-is, no "examples". You should be able to select text, press Ctrl+C, and then paste (Ctrl+V) text back into the QTextEdit or elsewhere since it is on your clipboard.

      Assuming you are using a platform where Ctrl+C is the "copy shortcut".

      W 1 Reply Last reply
      0
      • W WorldTeacher

        I have an application designed in QtDesigner and in it, there's a QTextEdit in which I put data from a query. I want to allow the user to select and copy text using the shortcut ctrl+c, but I can't seem to get it to work. The quick search I've done only shows examples on how to do it using buttons.

        Can I enable the copying using the shortcut? And if yes, how would I do it?

        Any answer is appreciated.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #3

        @WorldTeacher For me copying text via Strg-C from QTextEdit work just fine out of the box (Linux).

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

        1 Reply Last reply
        0
        • JonBJ JonB

          @WorldTeacher
          It should be working as-is, no "examples". You should be able to select text, press Ctrl+C, and then paste (Ctrl+V) text back into the QTextEdit or elsewhere since it is on your clipboard.

          Assuming you are using a platform where Ctrl+C is the "copy shortcut".

          W Offline
          W Offline
          WorldTeacher
          wrote on last edited by
          #4

          @JonB I'm on Windows 10 and currently, whenever I press ctrl+c, it doesn't copy the text I've marked.

          I'll do a quick test to see if a hunch I have is correct.

          W 1 Reply Last reply
          0
          • W WorldTeacher

            @JonB I'm on Windows 10 and currently, whenever I press ctrl+c, it doesn't copy the text I've marked.

            I'll do a quick test to see if a hunch I have is correct.

            W Offline
            W Offline
            WorldTeacher
            wrote on last edited by
            #5

            @JonB I thought it might have something to do with me running the application directly from the .py file, so I built the application into an .exe, but copying still doesn't work. Here's how the QTextEdit is configured eb4cb296-1b53-485d-8f96-a75562da9ecf-grafik.png 2d70b83e-3ffd-4a91-8c46-3e8992f53bdd-grafik.png
            is there anything I need to change?

            JonBJ 1 Reply Last reply
            0
            • W WorldTeacher

              @JonB I thought it might have something to do with me running the application directly from the .py file, so I built the application into an .exe, but copying still doesn't work. Here's how the QTextEdit is configured eb4cb296-1b53-485d-8f96-a75562da9ecf-grafik.png 2d70b83e-3ffd-4a91-8c46-3e8992f53bdd-grafik.png
              is there anything I need to change?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @WorldTeacher
              Every property you see whose name is in bold means it is set to something other than the default.

              You might try:

              • focusPolicy: change off NoFocus?
              • inputMethodHints: change off ImhNone

              But these are literally wild guesses.

              You can see in textInteractionFlags that it's set for "text selectable by mouse or keyboard*, which looks right. Instead of keyboard Ctrl+C did you try right-click on selected text, does context menu offer Copy?

              Try creating a brand new QTextEdit and don't change anything at all on it. Does that work?

              jsulmJ W 2 Replies Last reply
              1
              • JonBJ JonB

                @WorldTeacher
                Every property you see whose name is in bold means it is set to something other than the default.

                You might try:

                • focusPolicy: change off NoFocus?
                • inputMethodHints: change off ImhNone

                But these are literally wild guesses.

                You can see in textInteractionFlags that it's set for "text selectable by mouse or keyboard*, which looks right. Instead of keyboard Ctrl+C did you try right-click on selected text, does context menu offer Copy?

                Try creating a brand new QTextEdit and don't change anything at all on it. Does that work?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @JonB said in How to copy highlighted text from QTextEdit, PyQt6:

                focusPolicy: change off NoFocus?

                Agree
                @WorldTeacher If the widget can't have focus then shortcuts will not work...

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

                JonBJ 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @JonB said in How to copy highlighted text from QTextEdit, PyQt6:

                  focusPolicy: change off NoFocus?

                  Agree
                  @WorldTeacher If the widget can't have focus then shortcuts will not work...

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @jsulm said in How to copy highlighted text from QTextEdit, PyQt6:

                  If the widget can't have focus then shortcuts will not work...

                  Ah ha! :)

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @WorldTeacher
                    Every property you see whose name is in bold means it is set to something other than the default.

                    You might try:

                    • focusPolicy: change off NoFocus?
                    • inputMethodHints: change off ImhNone

                    But these are literally wild guesses.

                    You can see in textInteractionFlags that it's set for "text selectable by mouse or keyboard*, which looks right. Instead of keyboard Ctrl+C did you try right-click on selected text, does context menu offer Copy?

                    Try creating a brand new QTextEdit and don't change anything at all on it. Does that work?

                    W Offline
                    W Offline
                    WorldTeacher
                    wrote on last edited by
                    #9

                    @JonB @jsulm Changing focusPolicy from NoFocus to ClickFocus made the trick , thanks for the help.

                    Originally, I used the NoFocus to disable tabbing into the field but some time after that I found the disable tab and I forgot to change the other settings back to default...

                    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