S
S
sig2011-10-02 13:31:53
Qt
sig, 2011-10-02 13:31:53

How to set up a slider in QTextEdit object from Framework'a Qt 4.7?

There is an instance of the QTextEdit class:

QTextEdit *info2 = new QTextEdit;
info2->setReadOnly(true);
info2->setMinimumHeight(300);
info2->setAlignment(Qt::AlignCenter);

I sequentially load information from the *.txt file into it:
QString str;
QFile LicenseFile("E:/Qt/License.txt");
if (!LicenseFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&LicenseFile);
while (!in.atEnd())
{ str = in.readLine();
info2->append(str);}
LicenseFile.close();

Question: what method should be called so that the text block slider at the moment the window is opened is not scrolled to the end of the QTextEdit window.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bfDeveloper, 2011-10-02
@sig

The fact is that QTextEdit has automatic scrolling control so that the cursor is always visible (perhaps for something else). Cursor control methods will help you, for example:


edit->moveCursor (QTextCursor::Start); //или QTextCursor::End
edit->ensureCursorVisible() ;

If cursors are needed for other purposes, then you have to think about it. Although the question is well googled on English forums, so you can get out.

R
Riateche, 2011-10-02
@Riateche

If I'm not mistaken, it's done like this:

QScrollBar* bar = info2->verticalScrollBar();
bar->setValue(bar->minimum());
Keywords in QTextEdit documentation: "Inherits QAbstractScrollArea".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question