Commit 75c1522c authored by Romain Vimont's avatar Romain Vimont Committed by Hugo Beauzée-Luyssen

qt: improve time tooltip for hidpi

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.

It also fixes #20011 as a side effect.
Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent f1faf78d
......@@ -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 )
......
......@@ -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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment