PDA

View Full Version : How can I make the cursor flash?



cslijy
31st December 2007, 03:51
I paint a cursor in my textedit ,but it not flash,how can i make the cursor flash?




void MYTextEdit:: paintEvent(QPaintEvent *event)
{
QPainter p(viewport());
QTextLayout textLayout(document()->toPlainText());
QPointF t(100,100);

int leading = fm.leading();
int height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;

line.setLineWidth(200);
height += leading;
line.setPosition(QPoint(0, height));
height += (int) line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
textLayout.drawCursor(&p,t,2,3);
}
}

jpn
31st December 2007, 06:33
You'd have to run a timer to turn the cursor on and off. Anyways, have you noticed upcoming QPlainTextEdit (http://doc.trolltech.com/main-snapshot/qplaintextedit.html)? :)

elcuco
1st January 2008, 12:51
You'd have to run a timer to turn the cursor on and off. Anyways, have you noticed upcoming QPlainTextEdit (http://doc.trolltech.com/main-snapshot/qplaintextedit.html)? :)

sweet

Now my code contains these ugly lines:


#if QT_VERSION >= 0x040400
# define QTextEditorControl QPlainTextEdit
# warning "Using QPlainTextEdit as the text editor control"
#else
# define QTextEditorControl QTextEdit
#endif


(it crashes, but I will figure out whats wrong with it eventually)