Unsolved Key bindings for Transcript window using QTextBrowser
-
case Qt::Key_Left : QTextEdit::keyPressEvent(e); break;
}
This not working
-
@Qt-Enthusiast
Ok.
try
case Qt::Key_Left :
qDebug() << "Left pressed";
QTextEdit::keyPressEvent(e);
break;
}
and see if that part of code is executed. -
yes it working QTextEdit::keyPressEvent(e); not having a effect
-
@Qt-Enthusiast
So the cursor do not move 1 step to the left ? -
Yes it did not work
-
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 ?
-
yes it is QTextBrowser and we are calling QTextEdit::keyPressEvent( event);
is this a problem -
@Qt-Enthusiast
Could be if QTextBrowser override keypress to do its own stuff. else not. -
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? -
it is because of legacy code
-
@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. -
not working in my case in case of QTextEdit
-
@Qt-Enthusiast
not sure it will work very well with QTextBrowser