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. How to detect if a data in a QTableWidget cell is about to change
Forum Updated to NodeBB v4.3 + New Features

How to detect if a data in a QTableWidget cell is about to change

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 5.5k Views 1 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.
  • K Offline
    K Offline
    karim24
    wrote on last edited by
    #1

    what i mean is if someone double clicks it or pressing F2 in order to start typing i tried the signals:
    @void cellDoubleClicked(int row, int column)@
    @void cellEntered(int row, int column)@
    @void itemDoubleClicked(QTableWidgetItem * item)@
    @void itemEntered(QTableWidgetItem * item)@

    but the slots doesn't get excuted

    please note that i don't mean that the data is already changed ,but i mean before the data gets changed

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi, The cellEntered is a mouse operation detection, not a clicked signal, so you have to turn on the mousetracking option (see docs).
      The cellDoubleClicked should work or the
      @void QTableWidget::cellPressed(int row, int column) [signal]
      or
      void QTableWidget::cellActivated(int row, int column) [signal]
      @
      should both do the trick. My guess is that your connect isn't valid, so Qt doesn't make a connection for your event, so your slot doesn't get called. Check your application output for errors on connect function.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pkjag
        wrote on last edited by
        #3

        Why don't you try reimplementing
        @
        QItemSelectionModel
        @

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thEClaw
          wrote on last edited by
          #4

          If you want to detect changes, catch the proper signal.
          "QTableWidget::cellChanged()":http://qt-project.org/doc/qt-5.1/qtwidgets/qtablewidget.html#cellChanged
          "QTableWidget::itemChanged":http://qt-project.org/doc/qt-5.1/qtwidgets/qtablewidget.html#itemChanged
          These should be emitted right before the new data is made visible, at least that's the case in other views I have experience with.

          If that doesn't work, create the signal you need. Subclass "QStyledItemDelegate":http://qt-project.org/doc/qt-5.1/qtwidgets/qstyleditemdelegate.html and reimplement (in the most basic manner) "QAbstractItemDelegate::setModelData":http://qt-project.org/doc/qt-5.1/qtwidgets/qabstractitemdelegate.html#setModelData . Somewhat like this:
          @void YourStyledItemDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
          {
          emit YourCustomSignal(index);//if you need to transmit any data, index should contain enough information
          QStyledItemDelegate::setModelData(editor, model, index);
          }@

          And in the end you need to use your custom ItemDelegate with this function, which should be public for your QTableWidget:
          @QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate)@

          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