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
QtWS25 Last Chance

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.
  • M Offline
    M Offline
    maximus
    wrote on 14 May 2014, 21:31 last edited by aha_1980 3 Jan 2019, 19:33
    #1

    Hi,

    I would like to set a special cursor when the column 0 is hovered in my QTableView.
    Here is an example of what I would like :
    https://www.dropbox.com/s/88g5l5tu1f7bjgz/hoverCursor.png

    I already use a custom QStyledItemDelegate on my QTableView, I thought it would be possible to set it there but I haven't found anything working yet. I also searched for a way to modify my custom QAbstractTableModel and maybe returning a cursor from the data() function.

    The other way I tried is subclassing QTableView and reimplementing mouseMoveEvent, I can get the cursor this way but it breaks the drag&drop which is coded in my QAbstractTableModel(dropMimeData). I think coding this in the QTableView is bad practice anyway but i'm looking for a way to do it..

    Maybe I could add a custom Widget and set it cursor to a special one in the column I want (in every rows), but this sounds also bad and memory intensive.

    Thanks if anyone can help me, also if you work from Qt, I would like to know if paid support exist for Qt so I could get more help?
    Thank you!


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