[vlc-devel] [PATCH 1/2] qt: improve time tooltip for hidpi
Romain Vimont
rom1v at videolabs.io
Thu May 3 11:03:18 CEST 2018
On Thu, May 03, 2018 at 10:49:10AM +0200, Hugo Beauzée-Luyssen wrote:
> 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?
When setting a mask to a widget, it receives mouse events only on its
visible portions: <http://doc.qt.io/qt-5/qwidget.html#setMask>
If you click outside the mask, then the events are generated on the
widget "below" (as if the current widget were not present).
Here, we don't set a custom mask anymore, so the whole rectangle around
the tooltip captures mouse events. Since it is partially over the
seekbar, it prevents to seek correctly (cf video in #20011).
We never need to capture mouse events on the tooltip itself, so we can
make it completely "transparent" so that all mouse events pass through
it.
>
> 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
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list