Skip to content

Commit

Permalink
fix: 修复清除按钮的文字内容与右侧的边距和时间信息的边距不一致的问题
Browse files Browse the repository at this point in the history
修改控件宽度随字体大小自适应变化

Log: 修复清除按钮文字内容与右侧边距和时间的边距不一致的问题
Bug: https://pms.uniontech.com/bug-view-160153.html
Influence: 剪切板
Change-Id: Ib2afa54a07fbb04602f3e3280742e3e933517048
  • Loading branch information
Mars-cb authored and deepin-bot[bot] committed Sep 23, 2022
1 parent 5e5ecc0 commit 1002671
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions dde-clipboard/iconbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ void IconButton::paintEvent(QPaintEvent *event)
}
}

QSize IconButton::sizeHint() const
{
qDebug() << Q_FUNC_INFO;
return QSize(fontMetrics().width(m_text) + 20, fontMetrics().height() + 10);
}

void IconButton::resizeEvent(QResizeEvent *event)
{
resize(QSize(fontMetrics().width(m_text) + 20, fontMetrics().height() + 10));
DWidget::resizeEvent(event);
}

/*!
* \~chinese \name setFocusState
* \~chinese \brief 控制按钮被选中时,设置m_hasFocus的状态
Expand Down
2 changes: 2 additions & 0 deletions dde-clipboard/iconbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class IconButton : public DWidget
* \~chinese \param event 事件
*/
virtual void leaveEvent(QEvent *event) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual QSize sizeHint() const override;
};

#endif // ICONBUTTON_
1 change: 1 addition & 0 deletions dde-clipboard/itemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ void ItemWidget::initUI()
titleLayout->setSpacing(0);
titleLayout->setContentsMargins(10, 0, 10, 0);
titleLayout->addWidget(m_nameLabel);
titleLayout->addStretch();
titleLayout->addWidget(m_timeLabel);
titleLayout->addWidget(m_closeButton);

Expand Down
6 changes: 4 additions & 2 deletions dde-clipboard/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,18 @@ void MainWindow::initUI()
QWidget *titleWidget = new QWidget;
QHBoxLayout *titleLayout = new QHBoxLayout(titleWidget);
titleLayout->setContentsMargins(20, 0, 10, 0);
titleLayout->setAlignment(Qt::AlignVCenter);

QLabel *titleLabel = new QLabel(tr("Clipboard"), this);
titleLabel->setFont(DFontSizeManager::instance()->t3());
DFontSizeManager::instance()->bind(titleLabel, DFontSizeManager::T3);

m_clearButton = new IconButton(tr("Clear all"), this);
connect(m_clearButton, &IconButton::clicked, m_model, &ClipboardModel::clear);

titleLayout->addWidget(titleLabel);
titleLayout->addStretch();
titleLayout->addWidget(m_clearButton);
m_clearButton->setFixedSize(100, 36);
m_clearButton->setFixedHeight(36);
m_clearButton->setBackOpacity(200);
m_clearButton->setRadius(8);
m_clearButton->setVisible(false);
Expand Down

0 comments on commit 1002671

Please sign in to comment.