Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Key bindings for Transcript window using QTextBrowser
Qt 6.11 is out! See what's new in the release blog

Key bindings for Transcript window using QTextBrowser

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 2 Posters 2.9k Views 2 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.
  • Q Qt Enthusiast
    case Qt::Key_Left :
      
        QTextEdit::keyPressEvent(e);
        break;
    

    }

    This not working

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #5

    @Qt-Enthusiast
    Ok.
    try
    case Qt::Key_Left :
    qDebug() << "Left pressed";
    QTextEdit::keyPressEvent(e);
    break;
    }
    and see if that part of code is executed.

    1 Reply Last reply
    1
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on last edited by
      #6

      yes it working QTextEdit::keyPressEvent(e); not having a effect

      mrjjM 1 Reply Last reply
      0
      • Q Qt Enthusiast

        yes it working QTextEdit::keyPressEvent(e); not having a effect

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #7

        @Qt-Enthusiast
        So the cursor do not move 1 step to the left ?

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #8

          Yes it did not work

          mrjjM 1 Reply Last reply
          0
          • Q Qt Enthusiast

            Yes it did not work

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #9

            @Qt-Enthusiast

            Ok, i tried a test

            class MyTextEdit : public QTextEdit {
             public:
              explicit MyTextEdit(QWidget* parent = 0) : QTextEdit(parent) {}
             protected:
              virtual void keyPressEvent(QKeyEvent* event) override {
                QTextEdit::keyPressEvent( event);
              }
            };
            
            

            and it does work as expected. cursor moves left.

            btw in topic title you talk about QTextBrowser. You switched to QTextEdit ?

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on last edited by
              #10

              yes it is QTextBrowser and we are calling QTextEdit::keyPressEvent( event);
              is this a problem

              mrjjM 1 Reply Last reply
              0
              • Q Qt Enthusiast

                yes it is QTextBrowser and we are calling QTextEdit::keyPressEvent( event);
                is this a problem

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #11

                @Qt-Enthusiast
                Could be if QTextBrowser override keypress to do its own stuff. else not.

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #12

                  Ah
                  Just tried a Text Browser. as name implies its read only so it has no cursor to move around
                  by keypresses. why not use QTextEdit instead if you want user to input things?

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by
                    #13

                    it is because of legacy code

                    mrjjM 1 Reply Last reply
                    0
                    • Q Qt Enthusiast

                      it is because of legacy code

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #14

                      @Qt-Enthusiast
                      Ok. but TextBrowser seems to ignore it since its read only.

                      class MyTextEdit : public QTextBrowser {
                       public:
                        explicit MyTextEdit(QWidget* parent = 0) : QTextBrowser(parent) {}
                       protected:
                        virtual void keyPressEvent(QKeyEvent* event) override {
                          qDebug() << "HERE";
                          QTextBrowser::keyPressEvent( event);
                        }
                      };
                      
                      

                      KeyPressed is not called since its readOnly.

                      It does react to
                      ui->browser->moveCursor(QTextCursor::Left, QTextCursor::MoveAnchor);
                      ui->browser->textCursor().insertText("1");
                      but cursor is NOT visible.

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        Qt Enthusiast
                        wrote on last edited by
                        #15

                        not working in my case in case of QTextEdit

                        mrjjM 1 Reply Last reply
                        0
                        • Q Qt Enthusiast

                          not working in my case in case of QTextEdit

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #16

                          @Qt-Enthusiast
                          not sure it will work very well with QTextBrowser

                          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
                          • Unsolved