Results 1 to 10 of 10

Thread: Table model / view editing issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Table model / view editing issue

    Quote Originally Posted by Caius Aérobus
    it does not work with QAbstractTableModel. Does it mean that QAbstractTableModel. is also not editable?
    QAbstractTableModel is only an interface to any kind of a tabular model.

    Quote Originally Posted by Caius Aérobus
    I can edit the values in the table and I would like the graphic be updated accordingly each time I change a value.
    Provided that you have implemented your model properly, it should happen automatically.

    void QAbstractItemModel::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) [signal]
    This signal is emitted whenever the data in an existing item changes. The affected items are those between topLeft and bottomRight inclusive (of the same parent).
    Note that this signal must be emitted explicitly when reimplementing the setData() function.

  2. #2
    Join Date
    Mar 2006
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: Table model / view editing issue

    This signal is properly emitted in my model:

    bool
    vadTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
    {
    if (index.isValid() && role == Qt::EditRole) {
    this->table[index.row()*C+index.column()] = value.toInt();
    emit dataChanged(index, index);
    return TRUE;
    }
    return FALSE;
    }

    but the question is: which slot of the QAbstractItemView subclass is this signal connected to?
    because I have to overwrite this slot code to handle the modifications properly.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Table model / view editing issue

    Quote Originally Posted by Caius Aérobus
    which slot of the QAbstractItemView subclass is this signal connected to?
    This one, I guess:
    void QAbstractItemView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) [virtual protected slot]
    This slot is called when items are changed in the model. The changed items are those from topLeft to bottomRight inclusive. If just one item is changed topLeft == bottomRight.

  4. #4
    Join Date
    Mar 2006
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: Table model / view editing issue

    Yes, I have read this in the doc and below is my code BUT:
    - if I iconize the window and then deiconize it, it works and the changes in coordinates appear, which means that the paintEvent() is properly handled,
    - but if I change the coordinates in the table view, the coordinates are really changed in the model but the graphic is not updated, and this message appears:

    QPainter::begin: Widget painting can only begin as a result of a paintEvent
    QPainter::setWindow(), painter not active

    I really do not understand how it works! please help!

    void
    vadControlPolygon::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    {
    this->paint();
    }

    void
    vadControlPolygon:aintEvent(QPaintEvent *event)
    {
    this->paint();
    }

    void
    vadControlPolygon:aint()
    {
    QPainter painter(this->viewport());
    painter.setWindow(0, 0, 100, 100);
    QStyleOptionViewItem option;
    this->polygon.setPoints(3,
    this->model()->data(this->model()->index(0, 0)).toInt(),
    this->model()->data(this->model()->index(0, 1)).toInt(),
    this->model()->data(this->model()->index(1, 0)).toInt(),
    this->model()->data(this->model()->index(1, 1)).toInt(),
    this->model()->data(this->model()->index(2, 0)).toInt(),
    this->model()->data(this->model()->index(2, 1)).toInt()
    );
    painter.drawPolygon(this->polygon);
    for (int i=0 ; i<3 ; i++)
    this->itemDelegate()->paint(&painter, option, this->model()->index(i, 0));
    }

  5. #5
    Join Date
    Mar 2006
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: Table model / view editing issue

    My problems have been solved simply by adding the following line:
    setDirtyRegion(viewport()->rect());
    Regards.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Table model / view editing issue

    Quote Originally Posted by Caius Aérobus
    void
    vadControlPolygon::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    {
    this->paint();
    }
    This should be something like:
    Qt Code:
    1. void
    2. vadControlPolygon::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    3. {
    4. QRect rect( calculateChangeRegion( topLeft, bottmRight ) );
    5. update( rect );
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 18th November 2009, 23:21
  2. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  3. Replies: 3
    Last Post: 5th October 2008, 23:41
  4. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  5. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50

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
  •  
Qt is a trademark of The Qt Company.