[vlc-devel] [PATCH 1/2] qt: improve time tooltip for hidpi
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Thu May 3 10:49:10 CEST 2018
Hi,
On Thu, May 3, 2018, at 10:21 AM, Romain Vimont wrote:
> The time tooltip (for the seek slider) was pixelated on hidpi screens.
>
> Both the polygon to draw the tooltip and the widget mask had low
> definition.
>
> Replace QPolygon by QPolygonF to fix the tooltip drawing.
>
> Currently, Qt does not support hidpi masks. Instead, disable the mask,
> set a translucent background and make the widget transparent for mouse
> events.
>
Could you clarify the implication of setting WA_TransparentForMouseEvents?
Otherwise LGTM
> It also fixes #20011 as a side effect.
> ---
> modules/gui/qt/util/timetooltip.cpp | 15 +++------------
> modules/gui/qt/util/timetooltip.hpp | 2 --
> 2 files changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/modules/gui/qt/util/timetooltip.cpp b/modules/gui/qt/util/
> timetooltip.cpp
> index 2e7e97d987..1314b520ea 100644
> --- a/modules/gui/qt/util/timetooltip.cpp
> +++ b/modules/gui/qt/util/timetooltip.cpp
> @@ -40,6 +40,8 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
> // Tell Qt that it doesn't need to erase the background before
> // a paintEvent occurs. This should save some CPU cycles.
> setAttribute( Qt::WA_OpaquePaintEvent );
> + setAttribute( Qt::WA_TranslucentBackground );
> + setAttribute( Qt::WA_TransparentForMouseEvents );
>
> // Inherit from the system default font size -5
> mFont = QFont( "Verdana", qMax( qApp->font().pointSize() - 5, 7 ) );
> @@ -91,7 +93,6 @@ void TimeTooltip::adjustPosition()
>
> resize( size );
> buildPath();
> - setMask( mMask );
> }
> }
>
> @@ -105,7 +106,7 @@ void TimeTooltip::buildPath()
> mPainterPath.addRect( mBox );
>
> // Draw the tip
> - QPolygon polygon;
> + QPolygonF polygon;
> polygon << QPoint( qMax( 0, mTipX - 3 ), mBox.height() )
> << QPoint( mTipX, mBox.height() + TIP_HEIGHT )
> << QPoint( qMin( mTipX + 3, mBox.width() ), mBox.height() );
> @@ -113,16 +114,6 @@ void TimeTooltip::buildPath()
>
> // Store the simplified version of the path
> mPainterPath = mPainterPath.simplified();
> -
> - // Create the mask used to erase the background
> - // Note: this is a binary bitmap (black & white)
> - mMask = QBitmap( size() );
> - QPainter painter( &mMask );
> - painter.fillRect( mMask.rect(), Qt::white );
> - painter.setPen( Qt::black );
> - painter.setBrush( Qt::black );
> - painter.drawPath( mPainterPath );
> - painter.end();
> }
>
> void TimeTooltip::setTip( const QPoint& target, const QString& time,
> const QString& text )
> diff --git a/modules/gui/qt/util/timetooltip.hpp b/modules/gui/qt/util/
> timetooltip.hpp
> index d239d9984b..e7e57f622a 100644
> --- a/modules/gui/qt/util/timetooltip.hpp
> +++ b/modules/gui/qt/util/timetooltip.hpp
> @@ -25,7 +25,6 @@
> #include "qt.hpp"
>
> #include <QWidget>
> -#include <QBitmap>
>
> class QPaintEvent;
> class QString;
> @@ -54,7 +53,6 @@ private:
> QFont mFont;
> QRect mBox;
> QPainterPath mPainterPath;
> - QBitmap mMask;
> int mTipX;
> };
>
> --
> 2.17.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
--
Hugo Beauzée-Luyssen
hugo at beauzee.fr
More information about the vlc-devel
mailing list