forked from QNnovation/ZBC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbc_lineedit.cpp
53 lines (41 loc) · 1.23 KB
/
zbc_lineedit.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
#include "zbc_lineedit.h"
#include <QKeyEvent>
//C-tor
ZBC_LineEdit::ZBC_LineEdit(QWidget* pwgt) : QLineEdit(pwgt)
{
m_pltBackground.setColor(QPalette::Base, QColor(192, 192, 192));
this->setPalette(m_pltBackground);
}
//
void ZBC_LineEdit::mouseDoubleClickEvent(QMouseEvent *pe)
{
this->setReadOnly(false);
m_pltBackground.setColor(QPalette::Base, QColor(255, 255, 255));
this->setPalette(m_pltBackground);
m_strPath = this->text();
this->setCursorPosition(m_strPath.length());
QLineEdit::mouseDoubleClickEvent(pe);
}
//Focus out
void ZBC_LineEdit::focusOutEvent(QFocusEvent *pe)
{
if (!this->isReadOnly()){
this->setReadOnly(true);
m_pltBackground.setColor(QPalette::Base, QColor(192, 192, 192));
this->setPalette(m_pltBackground);
if (m_strPath != "")
this->setText(m_strPath);
}
QLineEdit::focusOutEvent(pe);
}
//Check if Enter is pressed
void ZBC_LineEdit::keyPressEvent(QKeyEvent *pe)
{
if ( pe->key() == Qt::Key_Return ){
emit pressedEnter(m_strPath);
this->setReadOnly(true);
m_pltBackground.setColor(QPalette::Base, QColor(192, 192, 192));
this->setPalette(m_pltBackground);
}
QLineEdit::keyPressEvent(pe);
}