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. QTableWidget - get column/row from under mouse ?
Forum Updated to NodeBB v4.3 + New Features

QTableWidget - get column/row from under mouse ?

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidget
9 Posts 3 Posters 4.7k Views 2 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    I'd like to print current row/column from under mouse position (in mouse move event) as well as item. I know I can get itemAt(event->pos()) for item, but if there is no item there I get null, how can I check what column/row that cursor is in now?

    TIA

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

      Hi,

      Can you show the current code you are using ?

      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
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        Actually I found out that I need cellEntered signal, but that does not happen as I'm dragging data in to the view, I just want to know whats under my mouse and if I need to make new cell/new data widget in cell or drop in to existing data widget in cell.

        Not much code yet... except for basic QDropEvent()/dragEnterEvent/dragMoveEvent events...

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

          The events you get as parameter gives you the position of the cursor. So you can check what's under it more precisely.

          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
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            You can use
            https://doc.qt.io/qt-5/qtablewidget.html#itemAt-1
            to get item under the cursor.
            You can then ask Item for Col/row if u need that.

            D 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              You can use
              https://doc.qt.io/qt-5/qtablewidget.html#itemAt-1
              to get item under the cursor.
              You can then ask Item for Col/row if u need that.

              D Offline
              D Offline
              Dariusz
              wrote on last edited by
              #6

              @mrjj said in QTableWidget - get column/row from under mouse ?:

              Hi
              You can use
              https://doc.qt.io/qt-5/qtablewidget.html#itemAt-1
              to get item under the cursor.
              You can then ask Item for Col/row if u need that.

              This return null if there is no item in column.

              @SGaist said in QTableWidget - get column/row from under mouse ?:

              The events you get as parameter gives you the position of the cursor. So you can check what's under it more precisely.

              I get no event when I'm dragging in a data from other widget/view/source.

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

                Can you show your current implementation ?

                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
                • D Offline
                  D Offline
                  Dariusz
                  wrote on last edited by Dariusz
                  #8

                  filterDropIndator() is where I try to figure out the position of the mouse...

                  
                  void TableWidget::dragEnterEvent(QDragEnterEvent *event) {
                      if (event->source() == this) {
                          qDebug() << "Internal";
                          setDragDropMode(QAbstractItemView::InternalMove);
                      } else {
                          qDebug() << "External";
                          setDragDropMode(QAbstractItemView::DropOnly);
                      }
                      if (event->mimeData()->hasFormat("templateItemDrag")) {
                          qDebug() << "111" << event << "\n3213213" << event->proposedAction() << event->possibleActions() << event->dropAction();
                          event->acceptProposedAction();
                      }
                      //QAbstractItemView::dragEnterEvent(event);
                  }
                  void TableWidget::dragMoveEvent(QDragMoveEvent *event) {
                      event->accept();
                      filterDropIndator(event);
                      //QAbstractItemView::dragMoveEvent(event);
                  }
                  void TableWidget::dragLeaveEvent(QDragLeaveEvent *event) {
                      QAbstractItemView::dragLeaveEvent(event);
                  }
                  void TableWidget::dropEvent(QDropEvent *event) {
                      qDebug() << "yay ?v3whyg345hg3w";
                      if (event->mimeData()->hasFormat("templateItemDrag")) {
                          qDebug() << "2132145215215";
                          event->acceptProposedAction();
                          return;
                      }
                      QTableWidget::dropEvent(event);
                  }
                  TableWidget::TableWidget(QWidget *parentPtr) : QTableWidget(parentPtr) {
                      setAcceptDrops(true);
                      setDragEnabled(true);
                      //viewport()->setAcceptDrops(true);
                      //setDragDropOverwriteMode(false);
                      setDropIndatorShown(true);
                      setDefaultDropAction(Qt::MoveAction);
                      setColumnCount(10);
                      setRowCount(1);
                      connect(this, &QTableWidget::cellEntered, this, &TableWidget::newMousePos);
                  }
                  TableWidget::~TableWidget() {
                  
                  }
                  void TableWidget::filterDropIndator(QDragMoveEvent *event) {
                      auto *w = itemAt(event->pos());
                      if (w) {
                  
                      } else {
                          qDebug() << "Row pos/col = " << mRow << mColumn;
                      }
                      qDebug() << "filtering indator :" << w;
                  
                  }
                  void TableWidget::newMousePos(int row, int column) {
                      mRow = row;
                      mColumn = column;
                  }
                  
                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dariusz
                    wrote on last edited by
                    #9

                    Ok solved, Im gigantic NUB. I used itemAt instead of indexAt and took me a while to notice it... everything works! thanks!!!

                    1 Reply Last reply
                    2

                    • Login

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