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. Input trough QPlainTextEdit

Input trough QPlainTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
qplaintexteditbeginnermouse eventkeyboardinput
10 Posts 5 Posters 1.1k 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.
  • G Offline
    G Offline
    Grand_Titan
    wrote on last edited by
    #1

    Hello I am a QT beginner and I'm still learning cpp. I really have no idea how to implement a feature and have already asked a few ppl and I got answers that I didn't understand so it would mean a lot if someone could thoroughly explain a solution. I have a QPlainTextEdit that is readonly and I would like to make it receive mouse and keyboard input(Key presses, mouse position, mouse buttons) but only when it is in focus(is the last widget that was clicked on). I really have no idea how to implement this but if its possible I would prefer to work like those signals that when an input is detected it calls a function with the input as its parameter. Also I already have a lot of code using this QPlainTextEdit so I really don't want to make a new one with classes or something. But please give me any solution that might work. Thank you!

    Axel SpoerlA SGaistS 2 Replies Last reply
    0
    • G Grand_Titan

      Hello I am a QT beginner and I'm still learning cpp. I really have no idea how to implement a feature and have already asked a few ppl and I got answers that I didn't understand so it would mean a lot if someone could thoroughly explain a solution. I have a QPlainTextEdit that is readonly and I would like to make it receive mouse and keyboard input(Key presses, mouse position, mouse buttons) but only when it is in focus(is the last widget that was clicked on). I really have no idea how to implement this but if its possible I would prefer to work like those signals that when an input is detected it calls a function with the input as its parameter. Also I already have a lot of code using this QPlainTextEdit so I really don't want to make a new one with classes or something. But please give me any solution that might work. Thank you!

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @Grand_Titan
      Please share a bit more about the use case: What is supposed to happen with those mouse and keyboard events?

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • G Grand_Titan

        Hello I am a QT beginner and I'm still learning cpp. I really have no idea how to implement a feature and have already asked a few ppl and I got answers that I didn't understand so it would mean a lot if someone could thoroughly explain a solution. I have a QPlainTextEdit that is readonly and I would like to make it receive mouse and keyboard input(Key presses, mouse position, mouse buttons) but only when it is in focus(is the last widget that was clicked on). I really have no idea how to implement this but if its possible I would prefer to work like those signals that when an input is detected it calls a function with the input as its parameter. Also I already have a lot of code using this QPlainTextEdit so I really don't want to make a new one with classes or something. But please give me any solution that might work. Thank you!

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Grand_Titan why did you delete your other thread about this subject ? It would have given @Axel-Spoerl some information to get started.

        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
        0
        • G Offline
          G Offline
          Grand_Titan
          wrote on last edited by
          #4

          @SGaist cuz it was going nowhere and I figured it would be better making another one and explaining my issue in one message which it seems I have failed.
          @Axel-Spoerl so I'm making an emulator of an old processor and I have this QPlainTextEdit called plainTextDisplay it basically displays ascii from a buffer in the memory. Now I don't want to allow users to change the display text so I just set readonly to true. Now I want to add a way to interact with that QPlainTextEdit so that when it is in focus to act like its own little pc so that when I press keys on my keyboard they get sent to another input buffer. Now I'll know how to do that but I have no idea how to capture the keys or use them. If its possible I would like to have a onKeyPressed function or something with the key as its parameter. And then just have a basic check to see if the plainTextDisplay is in focus if it isn't then just do nothing with that function and if it is then do something.

          M 1 Reply Last reply
          0
          • G Grand_Titan

            @SGaist cuz it was going nowhere and I figured it would be better making another one and explaining my issue in one message which it seems I have failed.
            @Axel-Spoerl so I'm making an emulator of an old processor and I have this QPlainTextEdit called plainTextDisplay it basically displays ascii from a buffer in the memory. Now I don't want to allow users to change the display text so I just set readonly to true. Now I want to add a way to interact with that QPlainTextEdit so that when it is in focus to act like its own little pc so that when I press keys on my keyboard they get sent to another input buffer. Now I'll know how to do that but I have no idea how to capture the keys or use them. If its possible I would like to have a onKeyPressed function or something with the key as its parameter. And then just have a basic check to see if the plainTextDisplay is in focus if it isn't then just do nothing with that function and if it is then do something.

            M Offline
            M Offline
            mpergand
            wrote on last edited by
            #5

            @Grand_Titan said in Input trough QPlainTextEdit:

            If its possible I would like to have a onKeyPressed function or something with the key as its parameter. And then just have a basic check to see if the plainTextDisplay is in focus if it isn't then just do nothing with that function and if it is then do something.

            Use an Event Filter to your TextEdit should be a solution.
            Search the doc and this forum about installEventFilter() to learn how it works.

            1 Reply Last reply
            1
            • G Offline
              G Offline
              Grand_Titan
              wrote on last edited by
              #6

              @mpergand tried for the last 20mins barely found anything and I'm not sure how it works but from what I understood doesn't that interfere with other plainTextEdits like I cant really filter the event on a specific widget. Can you please just make me an example on my scenario?

              M 1 Reply Last reply
              0
              • G Grand_Titan

                @mpergand tried for the last 20mins barely found anything and I'm not sure how it works but from what I understood doesn't that interfere with other plainTextEdits like I cant really filter the event on a specific widget. Can you please just make me an example on my scenario?

                M Offline
                M Offline
                mpergand
                wrote on last edited by
                #7

                @Grand_Titan
                https://forum.qt.io/topic/119779/textedit-and-eventfilter-characters-not-appearing-on-ui-element

                Axel SpoerlA 1 Reply Last reply
                1
                • M mpergand

                  @Grand_Titan
                  https://forum.qt.io/topic/119779/textedit-and-eventfilter-characters-not-appearing-on-ui-element

                  Axel SpoerlA Offline
                  Axel SpoerlA Offline
                  Axel Spoerl
                  Moderators
                  wrote on last edited by
                  #8

                  @Grand_Titan
                  Adding to @mpergand: you may want to start with the event filter just debugging every incoming event on the plain text edit.
                  That way you will see, if the events you expect are delivered.
                  Without having looked at the details, it should actually receive mouse can key events. Even if read only, you can still copy text.

                  Software Engineer
                  The Qt Company, Oslo

                  1 Reply Last reply
                  0
                  • JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    I will just throw one other possibility in. Maybe you are saying you would get what you want if you left the QPlainTextEdit editable, not readonly? Then do your own "readonly" by rejecting/ignoring/removing new characters going into the text edit while having all its editing events (keys, mouses)? Just a thought.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      Grand_Titan
                      wrote on last edited by
                      #10

                      @mpergand Thanks I figured it out from that one. For now it seems to work just fine.
                      @JonB Thanks for the reply I toughed about that too but I'll try the eventfilter first.

                      1 Reply Last reply
                      0
                      • G Grand_Titan has marked this topic as solved on

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved