Results 1 to 2 of 2

Thread: CustomListWidgetItem setData -> call itemUpdated signal

  1. #1
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default CustomListWidgetItem setData -> call itemUpdated signal

    Hello,

    I have a CustomListWidgetItem and override the setData for my data, but I need to let the list know when the user data is changed.
    Looking into the QT code I found that in the base class ( QListWidgetItem ) a signal is sent, through the QListModel , which it is not accessible.

    Qt Code:
    1. class CustomListWidgetItem : public QListWidgetItem
    2. {
    3. ...
    4. void setData( int role, const QVariant & value )
    5. {
    6. switch(role)
    7. {
    8. case Qt::UserRole:
    9. item = value.value<Item>();
    10. UpdateDurationTimer();
    11. if (QListModel *model = (listWidget() ? qobject_cast<QListModel*> (listWidget()->model()) : 0))
    12. {
    13. model->itemChanged(this); // This code is not accessible
    14. }
    15. break;
    16. default:
    17. QListWidgetItem::setData(role , value);
    18. break;
    19. }
    20. }
    21. ....
    22. }
    To copy to clipboard, switch view to plain text mode 

    Is there any elegant thing to do to emit that signal from the derived class? As walk around I could create an object and call base::setData to let the base do all the work but I don't like to duplicate unnecessary data

    Thanks in advance

  2. #2
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: CustomListWidgetItem setData -> call itemUpdated signal

    If you need custom model/view, maybe you should reconsider using QListWidget and use QListView and QListModel instead.
    In order to make custom model view development flexible there is model/view framework in Qt. It is very well documented see: Model/View Programming and An Introduction to Model/View Programming.

Similar Threads

  1. toggled(bool) signal does not call my slot?
    By Asperamanca in forum Newbie
    Replies: 6
    Last Post: 22nd July 2010, 09:54
  2. Signal/slot or direct method call within a class
    By mike_the_tv in forum Newbie
    Replies: 6
    Last Post: 11th March 2010, 18:49
  3. Doxgen call graphs also for signal-slot calls?
    By zavulon in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2008, 15:29
  4. Replies: 6
    Last Post: 3rd September 2008, 14:27
  5. model/view call setdata() function help?
    By dolphins in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 01:58

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.