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
    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));
    }

  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

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

  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
    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.