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. update QTableWidget on item change
Forum Updated to NodeBB v4.3 + New Features

update QTableWidget on item change

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.1k 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.
  • U Offline
    U Offline
    user4592357
    wrote on 1 Sept 2017, 18:39 last edited by user4592357 9 Jan 2017, 18:39
    #1

    i have a class CustomDelegate (derived from QDialog). there i store a data member of type QTableWidget, and i've set a custom delegate (derived from QItemDelegate) on the table widget. i've also overridden createEditor(), setModelData(), setEditorData(), updateEditorGeometry() and eventFilter() methods.

    in createEditor() i create an object of a class CustomButton (derived from QPushButton) and on that button i installEventFilter() the delegate and return it, just as usual:

    QWidget *CustomDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const {
        CustomButton *button = new CustomButton(parent);
        const button->installEventFilter(const_cast<CustomDelegate*>(this));
        return button;
    }
    

    the code is supposed to open the editor (which contains some items) on button double click, and when the user chooses one of the items, the button is updated with text related to the item. simple. initially i have some rows with default text.

    setModelData() and setEditorData() do it, but they don't work as expected.

    when i choose an item, its info IS updated on the button. BUT i HAVE to go to another cell so that setModelData() and setEditorData() will be called and the table widget will be updated with the new info.

    if i don't go to another cell and hit ok button, my changes won't be saved, but if i go to another cell, i'll see the new info ON the cell and ok will remember my changes.

    what am i doing wrong?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Sept 2017, 21:09 last edited by
      #2

      Hi,

      Take a look at the Star delegate example. It shows what you want to achieve.

      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

      1/2

      1 Sept 2017, 18:39

      • Login

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