VirtualBox

Ignore:
Timestamp:
May 10, 2024 1:35:32 PM (12 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
163114
Message:

FE/Qt: bugref:10667: HiDPI fix for UIMarkableLineEdit.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/extensions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp

    r104546 r104575  
    207207}
    208208
    209 
    210209void UIMarkableLineEdit::mark(bool fError, const QString &strErrorMessage, const QString &strNoErrorMessage)
    211210{
     211    AssertPtrReturnVoid(m_pIconLabel);
    212212    const QIcon icon = fError ? UIIconPool::iconSet(":/status_error_16px.png") : UIIconPool::iconSet(":/status_check_16px.png");
     213    const int iIconMetric = qMin((int)(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * .625), height());
     214    const qreal fDevicePixelRatio = gpDesktop->devicePixelRatio(m_pIconLabel);
    213215    const QString strToolTip = fError ? strErrorMessage : strNoErrorMessage;
    214     const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
    215     const qreal fDevicePixelRatio = gpDesktop->devicePixelRatio(m_pIconLabel);
    216     QPixmap iconPixmap = icon.pixmap(QSize(iIconMetric, iIconMetric), fDevicePixelRatio);
    217     m_iIconMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    218     int iHeight = height() -  m_iIconMargin;
    219     iconPixmap = iconPixmap.scaledToHeight(iHeight, Qt::SmoothTransformation);
     216    const QPixmap iconPixmap = icon.pixmap(QSize(iIconMetric, iIconMetric), fDevicePixelRatio);
    220217    m_pIconLabel->setPixmap(iconPixmap);
     218    m_pIconLabel->resize(m_pIconLabel->minimumSizeHint());
    221219    m_pIconLabel->setToolTip(strToolTip);
    222 
     220    m_iIconMargin = (height() - m_pIconLabel->height()) / 2;
    223221    update();
    224222}
    225223
    226 void UIMarkableLineEdit::paintEvent(QPaintEvent *pEvent)
    227 {
    228     QLineEdit::paintEvent(pEvent);
    229     moveIconLabel();
    230 }
    231224void UIMarkableLineEdit::moveIconLabel()
    232225{
    233226    AssertPtrReturnVoid(m_pIconLabel);
    234     m_pIconLabel->setVisible(true);
    235     int iHeight = height() -  m_iIconMargin;
    236     m_pIconLabel->setGeometry(width() - iHeight - 0.5 * m_iIconMargin, 0.5 * m_iIconMargin, iHeight, iHeight);
     227    m_pIconLabel->move(width() - m_pIconLabel->width() - m_iIconMargin, m_iIconMargin);
    237228}
    238229
     
    241232    /* Call to base-class: */
    242233    QLineEdit::resizeEvent(pResizeEvent);
     234    moveIconLabel();
     235}
     236
     237void UIMarkableLineEdit::showEvent(QShowEvent *pShowEvent)
     238{
     239    /* Call to base-class: */
     240    QLineEdit::showEvent(pShowEvent);
    243241    moveIconLabel();
    244242}
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.h

    r104546 r104575  
    118118
    119119    /** Handles resize @a pEvent. */
    120     virtual void resizeEvent(QResizeEvent *pResizeEvent) RT_OVERRIDE;
    121     virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
     120    virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
     121    /** Handles show @a pEvent. */
     122    virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
    122123    void moveIconLabel();
    123124    void prepare();
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette