Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QEvent::ToolTip behavior
Forum Updated to NodeBB v4.3 + New Features

QEvent::ToolTip behavior

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rno1
    wrote on last edited by
    #1

    Hi,

    I have created a simple qt gui project with one push button and a tooltip to try to catch QEvent::ToolTip

    As per "QT event type doc ":http://qt-project.org/doc/qt-5.0/qtcore/qevent.html#Type-enum ToolTip should be emitted when a tooltip is requested.

    In my test program ToolTip event is emitted only when the tool is destroyed.

    Here are my files:

    mainwindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QHelpEvent>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:
    bool event(QEvent *event);

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H@

    main.cpp
    @#include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }
    @

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    bool MainWindow::event(QEvent *event)
    {
    if (event->type() == QEvent::ToolTip ) qDebug("ToolTip");

    }@

    Is it the intended behavior or is it a bug?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bootchk
      wrote on last edited by
      #2

      If what you want is to show a tooltip, then use QWidget::setTooltip() on your button. That is, let the Qt event handling work without your intervention.

      If what you want is to understand what is going on, I really don't have an answer. Hasn't your test program short-circuited the normal Qt event handling, by not calling the base class event handler? And the return type is bool, but you haven't explicitly returned True or False, what does the handler return and what does that mean to Qt, for example, that the event was not handled and it should be delegated to your window's parent?

      A search shows Qt tooltips might be platform dependent, that is, depend on the operating system? Have you disabled tooltips for all your windows?

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        In this way you are getting tooltip requests for the main window, not the button. It is probably at the end because you pause your mouse somewhere over the window while you reach the "x" button.
        Also you should call the default implementation inside the event() override to let Qt properly handle all the events you are not interested in handling yourself. Don't forget the return value too. Otherwise you might be facing very weird bahaviour if the events are not processed properly.

        Your approach is quite error prone. The tooltip is requested on the button so if you want to handle it in the main window a good way to do this is to install event filter like this:
        @
        MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        //install the filter
        ui->button->installEventFilter(this);
        

        }

        //and then override eventFilter...
        bool MainWindow::eventFilter(QObject *obj, QEvent *event)
        {
        if(obj == ui->button && event->type() == QEvent::ToolTip)
        {
        //do stuff...
        }

        return false; //let Qt handle the event further
        

        }
        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved