Results 1 to 3 of 3

Thread: QModelView update

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QModelView update

    Hey there,

    I've searched a bit on the forum,

    I'm not sure how to update the model from its delegate edit event.

    Qt Code:
    1. bool ZeChatRoom_delegate::editorEvent(QEvent *event,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index)
    4. {
    5. const ZeChatRoom_model* modelData = static_cast<const ZeChatRoom_model*>(index.model());
    6. ZeChatRoom_data * chatData = index.data().value<ZeChatRoom_data *>();
    7.  
    8. if (event->type() == QEvent::MouseButtonDblClick)
    9. {
    10. //QMouseEvent *mev = (QMouseEvent*)event;
    11.  
    12. modelData->getService().
    13. OpenChat(chatData->getRoomName() + '@' + modelData->getServer());
    14.  
    15. chatData->setClicked(true);
    16.  
    17. // Hey view could you update your display please ?
    18.  
    19. }
    20. else if (event->type() == QEvent::MouseButtonRelease)
    21. {
    22. chatData->setClicked(false);
    23.  
    24. // Hey view could you update your display please ?
    25. }
    26. return false;
    27. }
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QModelView update

    The delegate should use QAbstractItemModel::setData to modify the model (or some other custom method the model provides and that emits dataChanged()). Emition of dataChanged() signal will cause the view to redraw the item.

  3. The following user says thank you to wysota for this useful post:

    bunjee (22nd April 2008)

  4. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QModelView update

    Will do, thanks.

Similar Threads

  1. drawForeground update trouble
    By spud in forum Qt Programming
    Replies: 6
    Last Post: 28th March 2011, 00:46
  2. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 09:42
  3. immediate update of QT object
    By db in forum Newbie
    Replies: 3
    Last Post: 14th August 2007, 12:25
  4. why there is no update on maximize? [QTableWidget]
    By macias in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 15:01
  5. QSlider Update Problem
    By December in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2006, 04:02

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.