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. QTableView - change cursor when hovering specific column

QTableView - change cursor when hovering specific column

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 6.8k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 14 May 2014, 22:17 last edited by
    #2

    Hi,

    Did you call the base implementation of mouseMouveEvent in your reimplemenation ?

    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
    1
    • M Offline
      M Offline
      maximus
      wrote on 14 May 2014, 22:25 last edited by
      #3

      Ohh you found my newbie mistake, thanks! Working now, too bad I have to keep a class just for reimplementing a small function but it will do :)

      Code :

      @TableViewInterval::TableViewInterval(QWidget *parent) :
      QTableView(parent)
      {
      this->setMouseTracking(true);

      setStyle(new IntervalViewStyle(style()));
      

      }

      //////////////////////////////////////////////////////////////////////////////////////////////////////////////
      void TableViewInterval::mouseMoveEvent(QMouseEvent* event) {

      QPoint pos = event->pos();
      QModelIndex index = indexAt(pos);
      
      
      if (index.isValid())
      {
          /// Drag cursor when hoverwing first column
          if (index.column() == 0) {
              setCursor(Qt::PointingHandCursor);
          }
          else {
              setCursor(Qt::ArrowCursor);
          }
      }
      QTableView::mouseMoveEvent(event);
      

      }@


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 May 2014, 22:39 last edited by
        #4

        You can also use an eventFilter

        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
        • M Offline
          M Offline
          maximus
          wrote on 15 May 2014, 02:02 last edited by
          #5

          Thanks SGaist, would it be more efficient with an evenFilter?
          Now this function is triggered a lot of times, it seems to run well enough but not sure if it's the right way..

          How could I use event filter since the only even I have here is the mouse move event?


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 15 May 2014, 06:57 last edited by
            #6

            More ? Don't think so, it should be pretty much the same.

            That's the idea of the evenFilter, you test if it's the event you want on the widget you want and act accordingly :)

            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
            • B Offline
              B Offline
              Bikram Shishodia
              wrote on 20 Feb 2019, 08:19 last edited by
              #7

              Hi, I used the above code in my customTableView and Its changing the mouse cursor but from second time(Not for the first time).
              And when its changed to Hand cursor, Its not going back to Arrow cursor for another column.
              Looks like the move event is not calculating the pos() every time on mouse move.
              I have already installed the event filter and setMouseTracking as true.
              Is there anything I am missing?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 20 Feb 2019, 22:03 last edited by
                #8

                Hi and welcome to devnet,

                What version of Qt ?
                On what platform ?

                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
                • B Offline
                  B Offline
                  Bikram Shishodia
                  wrote on 1 Mar 2019, 12:51 last edited by
                  #9

                  Windows, QT 5.10.1

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 1 Mar 2019, 19:30 last edited by
                    #10

                    Can you test a more recent version of Qt ?

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

                    B 1 Reply Last reply 15 May 2019, 07:43
                    0
                    • S SGaist
                      1 Mar 2019, 19:30

                      Can you test a more recent version of Qt ?

                      B Offline
                      B Offline
                      Bikram Shishodia
                      wrote on 15 May 2019, 07:43 last edited by
                      #11

                      @SGaist
                      I am using 5.12.2. Still facing the same issue.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 15 May 2019, 22:07 last edited by
                        #12

                        Test on macOS with 5.12.2 and it's working as expected. As soon as you pass on the first column the cursor changes and stays the same until a different column is passed on.

                        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

                        • Login

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