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. How to set and show dynamic tooltips in QT 5.12.4 LTS using C++
Forum Updated to NodeBB v4.3 + New Features

How to set and show dynamic tooltips in QT 5.12.4 LTS using C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.3k Views
  • 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.
  • B Offline
    B Offline
    brochiha
    wrote on last edited by Christian Ehrlicher
    #1

    Im developing a quotegenerator for my employer that is linked to a mysql database. My boss has decided that he wants to be able to hover over check boxes and radio button and have the program show the price in a tooltip directly from the database. Since there is also a chance that these prices will be updated it is important that the tooltips reflect that updated data. Also, Im trying to avoid going and programming every single check box and radio button individually. Im attaching my code that I have so far, I cant figure out at the moment why it isnt working.

    QSqlQuery query;
    query.exec("TRUNCATE TABLE quoteTableTemp");
    
    //Here we need to iterate list of widgets and then assign the pricing tooltip
    
    
    for(int k = 0; k<listOfWidgets.count(); k++){
        qDebug() << "Looking at " << listOfWidgets.at(k)->objectName();
        query.exec("SELECT * FROM quoteTable where name = '"+listOfWidgets.at(k)->objectName()+"'");
        query.last();
        QString connectionName = query.value(2).toString();
        qDebug() <<"The connection name is " << connectionName;
    
        query.exec("SELECT * FROM quoteItems WHERE name = '"+connectionName+"'");
        query.last();
        int price = query.value(2).toInt();
        qDebug() << "the price is " << price;
        listOfWidgets.at(k)->setToolTip("$"+QString::number(price));
    
    
        qDebug() << "The real name is " << listOfWidgets.at(k)->objectName();
    
    
        if(MainWindow::findChild<QCheckBox *>("drivePulleyCheckBox")){
            qDebug() << "set checkbox tooltip";
           MainWindow::findChild<QCheckBox *>("drivePulleyCheckBox")->setToolTip("$"+QString::number(price));
        }
        else if(MainWindow::findChild<QRadioButton *>(listOfWidgets.at(k)->objectName())){
            qDebug() << "set radiobutton tooltip";
           MainWindow::findChild<QRadioButton *>(listOfWidgets.at(k)->objectName())->setToolTip("$"+QString::number(price));
        }
        qDebug() << "setting tooltips";
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @brochiha said in How to set and show dynamic tooltips in QT 5.12.4 LTS using C++:

      I cant figure out at the moment why it isnt working.

      What exactly does not work?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      B 1 Reply Last reply
      0
      • B Offline
        B Offline
        brochiha
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @brochiha said in How to set and show dynamic tooltips in QT 5.12.4 LTS using C++:

          I cant figure out at the moment why it isnt working.

          What exactly does not work?

          B Offline
          B Offline
          brochiha
          wrote on last edited by
          #4

          @Christian-Ehrlicher The tooltips do not show when I hover the mouse over them. My apologies for being unclear, I can see in the debug app output that it assigns the correct value to each check box or radio button but it does not show when hovered on with mouse.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            So when you set the tool tip during startup it works? I would create a small function which is called e.g. when a button is pressed which sets the tooltip to something else and see if it works then.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            B 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              So when you set the tool tip during startup it works? I would create a small function which is called e.g. when a button is pressed which sets the tooltip to something else and see if it works then.

              B Offline
              B Offline
              brochiha
              wrote on last edited by
              #6

              @Christian-Ehrlicher it works if the check box or radio button is already checked, however I want it to set on startup so I can hover over them without them needing to be checked. IF that makes sense. I apologize as i am a but of a noob with regards to QT and C++

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                So you should start with a simple project - when I created a simple ui, put a checkbox in it and set the tooltip in the designer it is shown in the preview no matter if the checkbox is checked or not (nor if it has focus or not)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                B 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  So you should start with a simple project - when I created a simple ui, put a checkbox in it and set the tooltip in the designer it is shown in the preview no matter if the checkbox is checked or not (nor if it has focus or not)

                  B Offline
                  B Offline
                  brochiha
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher I can set the tooltip in the Ui but it does not update with the mysql database that I have. which is where the problem is, hence the reason for the code I have written above. from everything I have done this SHOULD cause the tooltips to show however there has to be something that I am missing. The application output with qdebug shows that the tooltip is set it is just not displayed in the ui

                  JonBJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Setting a tooltip during runtime works fine for me:

                    int main(int argc, char **argv)
                    {
                        QApplication app(argc, argv);
                        int i = 0;
                        QPushButton pb("Push me");
                        QObject::connect(&pb, &QPushButton::clicked, &pb, [&pb, &i]()
                        {
                            pb.setToolTip(QString("id is: %1").arg(i++));
                        });
                        pb.show();
                        return app.exec();
                    }
                    

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1
                    • B brochiha

                      @Christian-Ehrlicher I can set the tooltip in the Ui but it does not update with the mysql database that I have. which is where the problem is, hence the reason for the code I have written above. from everything I have done this SHOULD cause the tooltips to show however there has to be something that I am missing. The application output with qdebug shows that the tooltip is set it is just not displayed in the ui

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @brochiha
                      If you are saying that you do see the qDebug() << "set ... tooltip"; lines producing output, then thought would be that the rather nasty findChild<> statements you are using are not addressing the widgets you think they are, so you don't see the tooltip where you expect? Or, something else is later clearing the tooltip? Whether there is a database involved or not is not relevant to the fact that setToolTip() does set a tooltip correctly, and you can follow the flow of your code via a debugger or with qDebug() statements.

                      1 Reply Last reply
                      1

                      • Login

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