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] Displaying a tooltip for QTreeWidgetItem when it's hovered without calling setTooltip() for every item
QtWS25 Last Chance

[SOLVED] Displaying a tooltip for QTreeWidgetItem when it's hovered without calling setTooltip() for every item

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.9k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I want to display a tooltip for QTreeWidgetItem that's hovered. However, getting a tooltip is not a very fast operation in my case, so I don't want to call setTooltip() for every single item. I want to do it on demand, on some event or signal. What's the easiest way to do it?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      This can be easily achieved when you return the tool tip text in the model:
      @
      QVariant MyModel::data ( const QModelIndex & index, int role ) const
      {
      if( role == Qt::ToolTipRole )
      return QVariant(...);
      else
      BaseClass::data(index, role);
      @

      Easy when you've subclassed your model. If not you can use a proxy model.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        [quote author="raven-worx" date="1375869431"]This can be easily achieved when you return the tool tip text in the model[/quote]

        True, but OP is using QTreeWidget, not QTreeView.

        (Z(:^

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #4

          So I should subclass QTreeWidget, create my custom model and call setModel() on that widget?

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            You can use QTreeView without subclassing, but it's a lot of work to code from Widget to View approach. If the issue is not too severe, I would vote against changing the current setup.

            ... actually coming to think about it, maybe you could subclass QTreeWidget. I don't know.

            (Z(:^

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              [quote author="sierdzio" date="1375870403"]True, but OP is using QTreeWidget, not QTreeView.[/quote]
              right...my fault.
              But the changes are minimal anyway. Instead of subclassing your tree widget or model, subclass QTreeWidgetItem and overrride it's data() method. Analog to what i suggested for the model.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Violet Giraffe
                wrote on last edited by
                #7

                That's an easy solution indeed, thanks.

                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