Я новичок, работающий над QT. В основном я создаю поле QTextEdit в QT, и я хочу, чтобы курсор отображался в начальной позиции.
Мой простой код:
#include "mainwindow.h"
#include <QApplication>
#include <QLabel>
#include <QFont>
#include <QtGui>
#include <QPixmap>
#include <QTextEdit>
#include <QTextCursor>
#include <QLineEdit>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
w.setStyleSheet("background-color: yellow;");
w.show();
QTextEdit *txt = new QTextEdit();
txt->setText("Text 1");
txt->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
txt->setFocus();
txt->setStyleSheet("background-color: rgba(255, 255, 255, 200);");
txt->setGeometry(10,20,100,30);
txt->show();
return a.exec();
}
Это создает простое текстовое поле в окне w.
Я не использую мышь или клавиатуру, потому что это встроенная аппаратная плата.
Но после отображения текста должен отображаться курсор.
Я пробовал различные способы отображения курсора в QTextEdit, например:
QTextCursor cursor;
QTextEdit *editor = new QTextEdit();
QTextCursor cursor(editor->textCursor());
cursor.movePosition(QTextCursor::Start);
cursor.setPosition(5);
cursor.setPosition(9, QTextCursor::KeepAnchor);
txt->moveCursor(QTextCursor::End,QTextCursor::MoveAnchor);
txt->setCursorWidth(20);
txt->setTextCursor(cursor);
Но ни один из методов не отображает курсор. Я просмотрел большинство сообщений в SO.
Кто-нибудь может помочь? Большое Вам спасибо.
P.S. На форумах QT до сих пор не найдено решений.
return a.exec()
в конце вашего main() - person Oleg Pyzhcov   schedule 22.05.2015