Get single caret for QLineEdit and QTextEdit with focus events

Get single caret for QLineEdit and QTextEdit with focus events

Content Index :

Get single caret for QLineEdit and QTextEdit with focus events
Tag : events , By : Nicholas Hunter
Date : November 23 2020, 01:01 AM

I think the issue was by ths following , The issue with multiple cursors happens because you have completely overridden the default behaviour, rather than reimplementing it.
Since it looks like you only need to listen in on focus events, I think an event-filter would be more appropriate.
class MainWindow(QtGui.QMainWindow):
    def __init__(self):

    def eventFilter(self, source, event):
        if event.type() == QtCore.QEvent.FocusIn:
            if source is self.textedit_desc:
                self.lineedit_ref.setCursorPosition(0) # left
                    "background-color: rgb(255, 255, 240);")
                self.textedit_desc.moveCursor(13) # end of line
        elif event.type() == QtCore.QEvent.FocusOut:
            if source is self.textedit_desc:
                    "background-color: rgb(243, 243, 243);")
            elif source is self.lineedit_ref:
                self.lineedit_ref.setCursorPosition(0) # left
        return super(MainWindow, self).eventFilter(source, event)

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Getting text from QLineEdit to append to QTextEdit upon QLineEdit returnpressed()

Tag : cpp , By : Liy
Date : March 29 2020, 07:55 AM
I wish did fix the issue. When you run your program, you should notice on the console the following Qt error output..
Object::connect: No such slot QTextEdit::append(lineEdit.text()) in ..

Qt: Synchronous QLineEdit and QTextEdit

Tag : qt , By : foxthrot
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , you can have a UpdateTextEdit slot in your window/dialog's class, like this:
void ExampleDialog::UpdateTextEdit(){
    QString str= ui->lineEdit1->text();
    str+= "\n";
    str+= ui->lineEdit2->text();
    str+= "\n";
    str+= ui->lineEdit3->text();
    str+= "\n";
    //add text from all your line edits

ExampleDialog::ExampleDialog(QWidget* parent):QDialog(parent),...{
    connect(ui->lineEdit1, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateTextEdit()));
    connect(ui->lineEdit2, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateTextEdit()));
    connect(ui->lineEdit3, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateTextEdit()));

How to change the focus of QLineEdit automatically to another QLineEdit after input satisfy a criterion?

Tag : qt , By : Ben Brown
Date : November 04 2020, 11:01 PM
hop of those help? You need to check if edt1.hasAcceptableInput() every time textChanged() signal is emitted, and call edt2.setFocus() if it does.
#include <QtWidgets>

int main(int argc, char** argv)
    QApplication a{argc, argv};

    QWidget w;
    QLineEdit lineEdit1;
    QLineEdit lineEdit2;
    //validator to accept two digits
    QRegExpValidator validator{QRegExp{"\\d{2}"}};
    QVBoxLayout layout{&w};

    QObject::connect(&lineEdit1, &QLineEdit::textChanged, [&](){

    return a.exec();

Qt novice: base class for QLineEdit and QTextEdit

Tag : qt , By : Imran
Date : March 29 2020, 07:55 AM
help you fix your problem There is no other way besides QWidget. The reason is that QLineEdit is inherited directly from QWidget. You can see the full hierarchy of Qt classes here

QLineEdit::textEdited() equivalent in QTextEdit?

Tag : qt , By : Gipsy.D
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
Privacy Policy - Terms - Contact Us © scrbit.com