Results 1 to 13 of 13

Thread: Signal when end edit Item

  1. #1
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal when end edit Item

    Hi all!

    I'm a beginner in QT.
    I've a QTableWidget (name: tmp_table), and i putting Items on it by:

    Qt Code:
    1. QTableWidgetItem *newItem1 = new QTableWidgetItem(tr("%1").arg(query.value(1).toString()));
    2. tmp_table->setItem(row, col++, newItem1);
    To copy to clipboard, switch view to plain text mode 

    Items are editable (on click or press F2).

    I would like to call ex. some_function() (ex. save value in the database) when user end editing a datan int to a QTableWidgetItem.
    How can I do it?

    Thaks a lot!

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal when end edit Item

    have a look at this signal QTableWidget::itemChanged.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal when end edit Item

    I've tried this :/

    Unfortunately itemChanged is calling when Item are creating and putting into TableWiew, non when user end editing :/

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal when end edit Item

    I dont understand. do you need to process an user's input in an item widget?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Signal when end edit Item

    The right signal should be QTableWidget::cellChanged ( int row, int column ). It is emitted when the content has changed = editing finished.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal when end edit Item

    Quote Originally Posted by Lykurg View Post
    The right signal should be QTableWidget::cellChanged ( int row, int column ). It is emitted when the content has changed = editing finished.
    it's almost equal to that which I specified
    Qt Code:
    1. void QTableWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)
    2. {
    3. if (QTableWidgetItem *item = model()->item(index))
    4. emit q->itemChanged(item);
    5. emit q->cellChanged(index.row(), index.column());
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal when end edit Item

    J-P Nurmi

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Signal when end edit Item

    Quote Originally Posted by spirit View Post
    it's almost equal to that which I specified
    Right, I see, while switching from the forum to the docs my brain substitute itemChanged with currentItemChanged which leads to my superfluous reply...

  9. #9
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal when end edit Item

    Quote Originally Posted by spirit View Post
    I dont understand. do you need to process an user's input in an item widget?
    I need to save data (call function, save_data() ) when user change text in Item.

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal when end edit Item

    maybe it's not a best solution,but anyway, block signals when you create items and then you can use itemChanged or cellChanged.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal when end edit Item

    Quote Originally Posted by spirit View Post
    maybe it's not a best solution,but anyway, block signals when you create items and then you can use itemChanged or cellChanged.
    ok! It's seems to work cellChanged, almost:

    how to disable cellChange when I'm creating and putting Item into TableWiew:
    Qt Code:
    1. QTableWidgetItem *newItem1 = new QTableWidgetItem(tr("%1").arg(query.value(1).toString()));
    2. tmp_table->setItem(row, col++, newItem1);
    To copy to clipboard, switch view to plain text mode 

    ?

  12. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Signal when end edit Item

    try this
    Qt Code:
    1. const bool isBlocked = tmp_table->blockSignals(true);
    2. //add items here
    3. tmp_table->blockSignals(isBlocked);
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #13
    Join Date
    Jul 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal when end edit Item

    I haven't tested with QTableWidget, but I know that with QListWidget there's a much better solution than using QListWidget::itemChanged and trying to block all the signals when adding/changing colors/setting flags, and doing anything else that "changes" the item.

    Try this...

    Qt Code:
    1. connect(ui.pTblItems->itemDelegate(), &QAbstractItemDelegate::commitData, this, &MyWidget::OnTblItemsCommitData);
    To copy to clipboard, switch view to plain text mode 

    Then implement the slot like this...

    Qt Code:
    1. void MyWidget::OnTblItemsCommitData(QWidget* pLineEdit)
    2. {
    3. QString strNewText = reinterpret_cast<QLineEdit*>(pLineEdit)->text();
    4. int nRow = ui.pTblItems->currentRow();
    5. // do whatever you need here....
    6. }
    To copy to clipboard, switch view to plain text mode 

    Like I said... I only tried this for QListWidget, so who knows it might not work at all for the table widget, but the two classes are pretty similar so I wouldn't be surprised if it worked. You might have to tweak that code a bit to make it table widget specific.

Similar Threads

  1. How to edit Horizontal Header Item in QTableWidget
    By ioannis in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2013, 19:50
  2. Help on QListWidget InternalMove item signal
    By tho97 in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2009, 02:13
  3. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  4. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  5. Replies: 8
    Last Post: 15th May 2007, 10:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.