-
Notifications
You must be signed in to change notification settings - Fork 3
/
qplaintexteditcursor.cpp
56 lines (46 loc) · 1.14 KB
/
qplaintexteditcursor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Modifier: Yuriy Kuzin
* as I told you got somwhere on stackoverflow
*/
#include <QPainter>
#include <QTimer>
#include <QDebug>
#include "qplaintexteditcursor.h"
QPlainTextEditCursor::QPlainTextEditCursor( QWidget* parent )
: QPlainTextEdit( parent )
{
bIsCursorVisible = true;
CursorTimer = new QTimer( this );
CursorTimer->setInterval( 750 );
connect( CursorTimer, SIGNAL( timeout() ), this, SLOT( slot_BlinkCursor() ));
CursorTimer->start();
}
QPlainTextEditCursor::~QPlainTextEditCursor()
{
}
void QPlainTextEditCursor::slot_BlinkCursor( )
{
if( bIsCursorVisible )
{
bIsCursorVisible = false;
}
else
{
bIsCursorVisible = true;
}
viewport()->update();
}
void QPlainTextEditCursor::paintEvent( QPaintEvent* pEvent )
{
QPainter oPainter( viewport() );
if( bIsCursorVisible )
{
QRect r = cursorRect();
r.setWidth(8);
oPainter.fillRect( r, QBrush(Qt::green) );
}
QPlainTextEdit::paintEvent( pEvent );
}
void QPlainTextEditCursor::keyPressEvent(QKeyEvent *event)
{
emit keyPressed(event);
}