fix(inputbox): Position of icon in inputbox is incorrect.

Description: 修复输入框图标位置有误的问题

Log: 修复输入框图标位置有误的问题
Bug: -
This commit is contained in:
zhangjiaping 2021-01-18 19:16:38 +08:00
parent 1a7f52b85c
commit 862f9bae71
3 changed files with 18 additions and 2 deletions

View File

@ -119,6 +119,20 @@ void SearchBarHLayout::initUI()
});
}
void SearchBarHLayout::focusIn() {
m_queryLineEdit->setFocus();
}
void SearchBarHLayout::focusOut() {
m_queryLineEdit->clearFocus();
if (! m_queryText->parent()) {
m_queryWidget->layout()->addWidget(m_queryText);
m_queryText->adjustSize();
}
m_queryWidget->setGeometry(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 15)) / 2 - 10, 0,
m_queryIcon->width() + m_queryText->width() + 10, 35)); //使图标回到初始位置
}
void SearchBarHLayout::clearText() {
m_queryLineEdit->setText("");
}
@ -133,8 +147,7 @@ bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event)
if (event->type()==QEvent::FocusIn) {
if (m_queryLineEdit->text().isEmpty()) {
m_animation->stop();
m_animation->setStartValue(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 10)) / 2, 0,
m_queryIcon->width() + m_queryText->width() + 10, 35));
m_animation->setStartValue(m_queryWidget->geometry());
m_animation->setEndValue(QRect(0, 0, m_queryIcon->width() + 5, 35));
m_animation->setEasingCurve(QEasingCurve::OutQuad);
m_animation->start();

View File

@ -34,6 +34,8 @@ public:
~SearchBarHLayout();
void clearText();
QString text();
void focusIn();
void focusOut();
protected:
bool eventFilter(QObject *watched, QEvent *event);

View File

@ -244,6 +244,7 @@ void MainWindow::bootOptionsFilter(QString opt)
*/
void MainWindow::clearSearchResult() {
m_searchLayout->clearText();
m_searchLayout->focusOut();
}
/**