PDA

View Full Version : Display Cursor on a QTextEdit



vk41286
19th May 2015, 10:25
Hi,

I am a newbie to QT. I am trying a new application.
To start with, I am trying to display a cursor on QText Edit box.

The sample code is here :


This is my main.cpp file



#include "mainwindow.h"
#include <QApplication>
#include <QLabel>
#include <QFont>
#include <QtGui>
#include <QPixmap>
#include "usb-serial-app.h"
#include <QTextEdit>
#include <QTextCursor>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextEdit *txt = new QTextEdit();
txt->setText("Text 1");
txt->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
txt->setAutoFillBackground(true);
txt->setStyleSheet("background-color: cyan;color : Brown;");
txt->setFont(QFont("Arial", 10, QFont::Bold));
txt->setAlignment(Qt::AlignCenter);
txt->setGeometry(10,20,100,30);


QTextCursor cursor(txt->textCursor());
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
txt->setTextCursor(cursor);

txt->show();
return a.exec();
}



Now the problem is, I am unable to display a cursor in the QTextEdit box.
Please help me.

I need to set the cursor blinking too.
I am using QT4.8.5

Thanks a lot.