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. [SOLVED] How to disable tooltips from QTableWidgetItem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to disable tooltips from QTableWidgetItem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 9.2k 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.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    Hi!

    After trying several strategies I couldn't disable tooltips from the cells of a QTableWidget.

    Any suggestion? Thanks!


    Qt Developer

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

      Tooltips don't appear out of nowhere. If they're there then you probably set them somewhere. To remove a tooltip from an item just don't set it at all or set it to an empty string, eg.
      @tableWidget->item(row, column)->setToolTip(QString());@

      1 Reply Last reply
      1
      • X Offline
        X Offline
        xtingray
        wrote on last edited by
        #3

        But what if there is no any tooltip related instruction in the whole QTableWidget class based I created?

        Here is my code in case you want to check it:
        http://www.maefloresta.com/portal/files/tupframestable.cpp

        It seems there is some kind of tooltip default action related to the QTableWidget/QTableWidgetItem classes.


        Qt Developer

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

          Nope, there isn't:
          @
          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);

          QTableWidget tw(1, 1);
          tw.setItem(0,0, new QTableWidgetItem("very long text that can't possibly fit"));
          tw.show();
          
          return a.exec();
          

          }
          @
          No tooltip.

          Your code is that of tablewidget and tablewidgetitem but it all depends on how it is used. Where are the items created and inserted into the table? Maybe the tooltips are set there?

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xtingray
            wrote on last edited by
            #5

            Well, after several tests finally I found the reason I was getting tooltips without calling the setToolTip() method. I was using "exotic" values (0x01, 0x02, 0x03) for the parameter role in the method "setData()":http://qt-project.org/doc/qt-5/qtablewidgetitem.html#setData

            I could confirm it adding some lines to your sample:
            @
            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);

            QTableWidget tw(1, 1);
            QTableWidgetItem *item = new QTableWidgetItem;
            item->setData(0x01, "very long text that can't possibly fit");
            item->setData(0x02, true);
            item->setData(0x03, "Guess what?"); // <- this will be the tooltip text
            tw.setItem(0, 0, item);
            
            tw.show();
            
            return a.exec(&#41;;
            

            }
            @


            Qt Developer

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              That's why there's Qt::UserRole which is the starting point for custom roles in your application

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xtingray
                wrote on last edited by
                #7

                Thank you! Nice hint :)


                Qt Developer

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

                  Yeah, I'd say you got what you deserved ;) That's the kind of errors enums were invented for. 0x3 happens to be the value of Qt::TooltipRole but nobody said it's gonna stay that way forever. It can become Qt::DestroyTheWorld in Qt6 and we'll know who to thank for the trouble ;)

                  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