fixed(tray):tray pos error

偶尔会出现托盘图标错位的问题
This commit is contained in:
shaojun 2019-12-14 20:12:18 +08:00
parent 0356c5ca54
commit 6ffbf9e39f
4 changed files with 26 additions and 12 deletions

View File

@ -49,11 +49,6 @@ void PowerStatusWidget::refreshIcon()
update();
}
QSize PowerStatusWidget::sizeHint() const
{
return QSize(26, 26);
}
void PowerStatusWidget::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);
@ -105,3 +100,18 @@ QPixmap PowerStatusWidget::getBatteryIcon()
return pix;
}
void PowerStatusWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
// 保持横纵比
if (position == Dock::Bottom || position == Dock::Top) {
setMaximumWidth(height());
setMaximumHeight(QWIDGETSIZE_MAX);
} else {
setMaximumHeight(width());
setMaximumWidth(QWIDGETSIZE_MAX);
}
}

View File

@ -41,7 +41,7 @@ signals:
void requestContextMenu(const QString &itemKey) const;
protected:
QSize sizeHint() const;
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *e);
private:

View File

@ -118,15 +118,20 @@ void SoundItem::invokeMenuItem(const QString menuId, const bool checked)
.call();
}
QSize SoundItem::sizeHint() const
{
return QSize(26, 26);
}
void SoundItem::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
// 保持横纵比
if (position == Dock::Bottom || position == Dock::Top) {
setMaximumWidth(height());
setMaximumHeight(QWIDGETSIZE_MAX);
} else {
setMaximumHeight(width());
setMaximumWidth(QWIDGETSIZE_MAX);
}
refreshIcon();
}

View File

@ -50,7 +50,6 @@ signals:
void requestContextMenu() const;
protected:
QSize sizeHint() const;
void resizeEvent(QResizeEvent *e);
void wheelEvent(QWheelEvent *e);
void paintEvent(QPaintEvent *e);