QTextEdit->ensureCursorVisible() with QScrollArea



  • Hi,

    In my program, I have a QWidget that contains a QScrollArea which itself contains two QTextEdit.
    I just want the QTextCursor remains visible, so the user sees what he's typing.
    I know there is a method "ensureCursorVisible()" in QTextEdit but, strangely, it does not work with a QScrollArea.
    I'm using this code for the moment:
    @layout_vertical = new QVBoxLayout;
    QTextEdit *textEdit = new QTextEdit;
    scrollArea = new QScrollArea;
    scrollArea->setAlignment(Qt::AlignHCenter);
    widget = new QWidget;
    layout_vertical->addWidget(document_onglet, 0, Qt::AlignHCenter);
    widget->setLayout(layout_vertical);
    MyQMdiSubWindow->setWidget(scrollArea);
    textEdit->setMaximumHeight(1500);
    textEdit->setMinimumHeight(1500);
    textEdit->setMinimumWidth(800);
    textEdit->setMaximumWidth(800);
    textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    textEdit->ensureCursorVisible();
    QTextEdit *o2 = new QTextEdit;
    o2->setMaximumHeight(1500);
    o2->setMinimumHeight(1500);
    o2->setMinimumWidth(800);
    o2->setMaximumWidth(800);
    layout_vertical->addWidget(o2, 0, Qt::AlignHCenter);
    scrollArea->setWidget(widget); @

    Everything is OK except except that the QScrollAreanot move when the cursor disappears "under the program."
    So, how can I force the cursor to remain visible?

    Thanks :D


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.