I am newbie working on QT. Basically I am creating a QTextEdit box in QT and I want the Cursor to display at initial position.
My Simple Code is :
#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();
}
This creates a simple Text box on a window w.
I am not using mouse or a keyboard because it for a embedded Hardware board.
But after displaying the text the cursor should be displayed.
I am tried various method to get cursor displayed on QTextEdit like :
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);
But none of the method displays cursor. I have done through most of the posts in SO.
Can anyone help? Thank you very much.
P.S : No solutions obtained in QT forums till now.