Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

"Blinking" tooltip



  • Hi,

    I'm using Qt5.7 32 bits bundled with MinGW, Win10 x64.

    I'm using a QLineEdit in a QWizardPage.
    I want the user to give a valid path.
    Here is a screenshot to visualize : http://www.mirari.fr/GRJw.png

    Here is the relevant part of the header:

    class PageParkLocation : public QWizardPage
    {
        public:
            PageParkLocation(QWidget* parent, QString title);
    
        private:
            QLineEdit* editLocation;
            bool isComplete() const override;
    

    As said in the QWizardPage documentation, I have overriden the isComplete method to ensure that the path is valid before the user may continue.

    Here is my code:

    bool PageParkLocation::isComplete() const
    {
        // Don't use the QDir(QString str) constructor, because the path is set to QDir::homePath() if str is empty
        QDir dir;
        dir.setPath(this->editLocation->text());
    
        // Complete is the return value, true if the user may continue, else false
        bool complete = dir.exists();
    
        if (complete || this->editLocation->text().isEmpty()) {
            // Don't draw any tooltip if the input is empty or invalid
            QToolTip::hideText();
        }
        else {
            // Show the tooltip just below the ```QLineEdit``` widget
            QPoint position = this->editLocation->mapToGlobal(QPoint(0, 10));
            QToolTip::showText(position, toolTipNotComplete, this->editLocation);
            }
        }
    
        return complete;
    }
    

    This looks really basic code.

    PROBLEM: But when the input is invalid, I get the tooltip shown only on on two characters (sorry, probably bad english).
    Example: When I type "ABCDEF", I will get the tooltip shown for 'A', 'C', 'E', and hidden for 'B', 'D' and 'F'. And obviously, I haven't any valid path like "AB", "ABCD" or "ABCDEF". So, the tooltip should appear every time I type a character.

    Some notes:

    • complete is computed correctly, because the "Next" button is never enabled when it should be disabled
    • if I set a QLabel visible/invisible with this logic, instead of aQToolTip, it works.
    • the toolTipNotComplete var is a static QString, but I get the same with a local string

    Thanks for any help. :)


  • Moderators

    @Folco
    Here is what happens:

    1. you type 'A'
    2. tooltip gets shown
    3. you type 'B' -> tooltip gets closed on key input (i guess since its a popup window)
    4. you type 'C' and show the tooltip again
    5. ...

    So using a tooltip is the wrong approach here. The actual intention of a tooltip is to show it on mouse hover.
    So you should go with your label approach.


Log in to reply