VirtualBox

Changeset 72871 in vbox


Ignore:
Timestamp:
Jul 4, 2018 12:02:36 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8694: Adjust icons when moving GUI between screen with different DPI: UIStatusBarEditorWindow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIStatusBarEditorWindow.cpp

    r72026 r72871  
    8888protected:
    8989
     90    /** Handles any Qt @a pEvent. */
     91    virtual bool event(QEvent *pEvent) /* override */;
     92
    9093    /** Handles translation event. */
    9194    virtual void retranslateUi() /* override */;
     
    106109
    107110private:
     111
     112    /** Prepares all. */
     113    void prepare();
     114
     115    /** Updates pixmap. */
     116    void updatePixmap();
    108117
    109118    /** Holds the button type. */
     
    207216    , m_fHovered(false)
    208217{
    209     /* Track mouse events: */
    210     setMouseTracking(true);
    211 
    212     /* Prepare icon for assigned type: */
    213     const QIcon icon = gpConverter->toIcon(m_enmType);
    214     const QStyle *pStyle = QApplication::style();
    215     const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    216     m_pixmapSize = QSize(iIconMetric, iIconMetric);
    217     m_pixmap = icon.pixmap(m_pixmapSize);
    218 
    219     /* Cache button size-hint: */
    220     QStyleOptionButton option;
    221     option.initFrom(this);
    222     const QRect minRect = QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &option);
    223     m_size = m_pixmapSize.expandedTo(minRect.size());
    224 
    225     /* Translate finally: */
    226     retranslateUi();
     218    prepare();
    227219}
    228220
     
    238230    /* Update: */
    239231    update();
     232}
     233
     234bool UIStatusBarEditorButton::event(QEvent *pEvent)
     235{
     236    /* Handle know event types: */
     237    switch (pEvent->type())
     238    {
     239        case QEvent::Show:
     240        case QEvent::ScreenChangeInternal:
     241        {
     242            /* Update pixmap: */
     243            updatePixmap();
     244            break;
     245        }
     246        default:
     247            break;
     248    }
     249
     250    /* Call to base-class: */
     251    return QIWithRetranslateUI<QWidget>::event(pEvent);
    240252}
    241253
     
    347359    pDrag->setPixmap(m_pixmap);
    348360    pDrag->exec();
     361}
     362
     363void UIStatusBarEditorButton::prepare()
     364{
     365    /* Track mouse events: */
     366    setMouseTracking(true);
     367
     368    /* Calculate icon size: */
     369    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     370    m_pixmapSize = QSize(iIconMetric, iIconMetric);
     371
     372    /* Cache button size-hint: */
     373    QStyleOptionButton option;
     374    option.initFrom(this);
     375    const QRect minRect = QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &option);
     376    m_size = m_pixmapSize.expandedTo(minRect.size());
     377
     378    /* Update pixmap: */
     379    updatePixmap();
     380
     381    /* Translate finally: */
     382    retranslateUi();
     383}
     384
     385void UIStatusBarEditorButton::updatePixmap()
     386{
     387    /* Recache pixmap for assigned type: */
     388    const QIcon icon = gpConverter->toIcon(m_enmType);
     389    if (window())
     390        m_pixmap = icon.pixmap(window()->windowHandle(), m_pixmapSize);
     391    else
     392        m_pixmap = icon.pixmap(m_pixmapSize);
    349393}
    350394
Note: See TracChangeset for help on using the changeset viewer.

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