I have QDialog
that contains few buttons and a QTextEdit
.
after writing something in the QTextEdit
, I press tab in order to get to one of the buttons, but when I pressing tab, a tab space is added to the QTextEdit
. How can I change this behavior?
Pressing Tab in QTextEdit in Dialog - change behavior
You can use setTabChangesFocus method of QTextEdit
:
yourTextEdit.setTabChangesFocus(true);
Works for PyQt5 as well. –
Marshmallow
You can subclass QTextEdit
and override the keyPressEvent
to intercept the tab key. Then, use nextInFocusChain
to determine the next focus widget and call setFocus
on it
Outline:
class MyTextEdit : public QTextEdit
{
public:
MyTextEdit(QWidget *parent = 0) : QTextEdit(parent) {}
protected:
void keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Tab) {
nextInFocusChain()->setFocus(Qt::TabFocusReason);
} else {
QTextEdit::keyPressEvent(e);
}
}
};
© 2022 - 2024 — McMap. All rights reserved.