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. Add tooltips for individual headers
Forum Updated to NodeBB v4.3 + New Features

Add tooltips for individual headers

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 3.3k Views 3 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.
  • Gojir4G Gojir4

    @pk23081996 Hi,

    You probably need to do this:

    myModel.horizontalHeaderItem(0)->setToolTip("Header 0");
    myModel.horizontalHeaderItem(1)->setToolTip("Header 1");
    
    P Offline
    P Offline
    pk23081996
    wrote on last edited by
    #3

    Hi @Gojir4, My model is subclassed from QAbstractTableModel. The methods you suggested are present in QTableWidget class but I am using QTableView here. Is there any workaround for that? This method is not available in QTableView.

    JonBJ Gojir4G 2 Replies Last reply
    0
    • P pk23081996

      Hi @Gojir4, My model is subclassed from QAbstractTableModel. The methods you suggested are present in QTableWidget class but I am using QTableView here. Is there any workaround for that? This method is not available in QTableView.

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

      @pk23081996

      • Are you sure "headerData() for role == Qt::toolTipRole" is not being hit? E.g. https://stackoverflow.com/a/13461087 seems close enough to your case but claims to work?

      • Since QTableWidget derives from QTableView, in principle if it can be done in the former you can do it too if you derive from the latter. You might want to look at the source code to see if the code is easy to copy for your situation?

      P 1 Reply Last reply
      2
      • JonBJ JonB

        @pk23081996

        • Are you sure "headerData() for role == Qt::toolTipRole" is not being hit? E.g. https://stackoverflow.com/a/13461087 seems close enough to your case but claims to work?

        • Since QTableWidget derives from QTableView, in principle if it can be done in the former you can do it too if you derive from the latter. You might want to look at the source code to see if the code is easy to copy for your situation?

        P Offline
        P Offline
        pk23081996
        wrote on last edited by
        #5

        Hi @JonB ,

        1.Yes I am sure about it as i tried putting debug statements inside the functions. Only the data() was getting hit.
        2.The point is the QTableWidget class uses QTableWidgetItem class which contains the setToolTip function. The QTableView doesn't contain this method.

        Can you just show me how you want me to do it?

        Thanks

        raven-worxR 1 Reply Last reply
        0
        • P pk23081996

          Hi @JonB ,

          1.Yes I am sure about it as i tried putting debug statements inside the functions. Only the data() was getting hit.
          2.The point is the QTableWidget class uses QTableWidgetItem class which contains the setToolTip function. The QTableView doesn't contain this method.

          Can you just show me how you want me to do it?

          Thanks

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #6

          @pk23081996 said in Add tooltips for individual headers:

          Can you just show me how you want me to do it?

          Are you using QTableView or a QTableWidget?! In your first post you said QTableView and you also claimed that you subclassed QAbstractTableModel.
          This is essential since a QTableWidget has it's own internal model.

          If its correct that implemented QAbstractTableModel, use QTableView and call setModel() on it. This applies the model to the view itself and also applies it to it's QHeaderView widget. Which definitely calls headerData().

          If not show us your code, you maybe have a different signature in your headerData() method, which has the effect that it is not called by the QHeaderView widget.

          --- 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

          P 1 Reply Last reply
          3
          • P pk23081996

            Hi @Gojir4, My model is subclassed from QAbstractTableModel. The methods you suggested are present in QTableWidget class but I am using QTableView here. Is there any workaround for that? This method is not available in QTableView.

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by
            #7

            @pk23081996 said in Add tooltips for individual headers:

            Hi @Gojir4, My model is subclassed from QAbstractTableModel. The methods you suggested are present in QTableWidget class but I am using QTableView here. Is there any workaround for that? This method is not available in QTableView.

            You're right I was on QStandartItemModel doc and not on QAbstractTableModel. My bad sorry.

            1 Reply Last reply
            0
            • raven-worxR raven-worx

              @pk23081996 said in Add tooltips for individual headers:

              Can you just show me how you want me to do it?

              Are you using QTableView or a QTableWidget?! In your first post you said QTableView and you also claimed that you subclassed QAbstractTableModel.
              This is essential since a QTableWidget has it's own internal model.

              If its correct that implemented QAbstractTableModel, use QTableView and call setModel() on it. This applies the model to the view itself and also applies it to it's QHeaderView widget. Which definitely calls headerData().

              If not show us your code, you maybe have a different signature in your headerData() method, which has the effect that it is not called by the QHeaderView widget.

              P Offline
              P Offline
              pk23081996
              wrote on last edited by
              #8

              @raven-worx Hi, I don't say it is not hitting headerData() but only not for QToolTipRole.

              0_1555585802556_f766d845-3e81-4dc7-afb4-efc343876dd8-image.png

              raven-worxR 1 Reply Last reply
              0
              • P pk23081996

                @raven-worx Hi, I don't say it is not hitting headerData() but only not for QToolTipRole.

                0_1555585802556_f766d845-3e81-4dc7-afb4-efc343876dd8-image.png

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #9

                @pk23081996
                anything else special about your model/tableview?

                Heres the corresponding implementation code which requests the data.

                --- 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

                P 1 Reply Last reply
                2
                • raven-worxR raven-worx

                  @pk23081996
                  anything else special about your model/tableview?

                  Heres the corresponding implementation code which requests the data.

                  P Offline
                  P Offline
                  pk23081996
                  wrote on last edited by
                  #10

                  @raven-worx Ya there is nothing special here, just that the role is not coming out to be ToolTipRole here.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gnc50
                    Banned
                    wrote on last edited by gnc50
                    #11
                    This post is deleted!
                    1 Reply Last reply
                    -1
                    • G Offline
                      G Offline
                      gnc50
                      Banned
                      wrote on last edited by gnc50
                      #12
                      This post is deleted!
                      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