Important: Please read the Qt Code of Conduct -

QToolTip StyleSheet with padding produces additional padding

  • I have found a strange thing concerning QToolTip. I use Qt 5.6 and above on Windows 10.
    I use a stylesheet for QToolTips with a padding. And now the first ToolTip has an additional padding. When I directly move on to the next widget and the tooltip changes without being hidden the next tooltip is correct and all other upcoming tooltips.
    But when I move the mouse away from the widgets and then back to one of the widgets with a tooltip, this issue shows again.

    Can someone confirm this?

    #include <QApplication>
    #include "mainwindow.h"
    #include <QPushButton>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        QWidget widget;
        widget.setStyleSheet( "QToolTip \
                               { \
                                   padding: 3px; \
                                   color: #000000; \
                                   background-color: #F4F4F4; \
                                   border: 1px solid #C0C0C0; \
                               }" );
        QGridLayout layout;
        widget.setLayout( &layout );
        for( int i = 1; i <= 5; i++ )
            QPushButton* button = new QPushButton( QString::number( i ), &widget );
            button->setToolTip( QString( "My Button %1" ).arg( i ) );
            layout.addWidget( button );
        return a.exec();

  • Hi @stvokr

    After test ,

    Under Windows 7 with Qt 5.5 , i confirm that i have the same behavior,

    alt text

    But in linux with Qt 5.4 there is no padding ,

    I do not know if it is a bug , or if it is just related to the OS style,

    Maybe other people can advise you more,

    But it could be a good idea to upgrade your qt version to 5.8 and to see if the problem is still present,

    Hope this can help !

  • Moderators

    @mostefa @stvokr

    sadly, with Qt 5.8 on Win10 x64 same behavoir

  • Hi,

    I have tested it on Linux, Qt 5.6, and on Windows 10 with Qt 5.8 msvc2015 and mingw.
    It works on Linux (see below), but still the same behavior on Windows 10.

  • Lifetime Qt Champion


    It might be a bug in the custom rendering of QToolTip when using a style sheet. You should check the bug report system to see it it's something known.

  • Hi,

    I have committed a new bug report.


Log in to reply