[Qt-interest] 2 QTextEdit: how to obtain a visible cursor in both at startup

TP paratribulations at free.fr
Fri Jan 14 09:56:57 CET 2011


Hello,

I have two QTextEdit in my application, with some correspondance between 
both. That is why, I want to show the cursor in both of them at startup.
To make the cursor always visible in a QTextEdit, I have found that an empty 
reimplementation of focusOutEvent makes the job (see the code below).
But I have not found a way to make both cursors appear at startup. For the 
time being, the user must click in the second QTextEdit for the cursor to be 
always visible.
I have tried to play with .setFocus() (see below), but this does not work, 
this is not equivalent to the user clicking in one text edit and then in the 
other, because the cursor remains in one of the text edit at startup, not in 
both.

Any idea?

Thanks a lot

Julien


#include <QtGui>
#include <QtCore>

class QTextEdit2 : public QTextEdit
{

public:
    void focusOutEvent( QFocusEvent * event );
};

void QTextEdit2::focusOutEvent( QFocusEvent * event )
{
}

int main( int argc, char * argv[] )
{
    QApplication app( argc, argv );
    QTextEdit2 text1;
    QTextEdit2 text2;

    QDialog dialog;
    dialog.resize( 750, 550 );

    QVBoxLayout qvboxlayout( &dialog );
    qvboxlayout.addWidget( &text1 );
    qvboxlayout.addWidget( &text2 );

    text2.setFocus();
    text1.setFocus();

    dialog.show();
    app.exec();
}




More information about the Qt-interest-old mailing list