-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
45 lines (41 loc) · 963 Bytes
/
widget.cpp
File metadata and controls
45 lines (41 loc) · 963 Bytes
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
#include "widget.h"
#include "ui_widget.h"
#include <QVBoxLayout>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
m_cursor = new MyCursor;
m_cursor->setFixedSize(2, 18);
QVBoxLayout *la = new QVBoxLayout;
la->addWidget(m_cursor);
setLayout(la);
}
Widget::~Widget()
{
delete ui;
}
void Widget::keyPressEvent(QKeyEvent *event)//获取键盘事件
{
Q_UNUSED(event)
if(event->key() == Qt::Key_Backspace)
{
QPoint p = m_cursor->pos();
QPoint sp = p;
QPoint ep = p;
ep.setX(sp.x() - 10);
m_cursor->setStartPoint(sp);
m_cursor->setEndPoint(ep);
m_cursor->moveNext();
}else{
QPoint p = m_cursor->pos();
QPoint sp = p;
QPoint ep = p;
ep.setX(sp.x() +10);
m_cursor->setStartPoint(sp);
m_cursor->setEndPoint(ep);
m_cursor->moveNext();
}
}