Results 1 to 4 of 4

Thread: datachange

  1. #1
    Join Date
    Nov 2012
    Posts
    38
    Thanks
    3

    Default datachange

    hello.
    I have access to a model in a custom delegate.
    I tryed to change some values in this model but when I read data from the model the data are always the same.
    I tryed to emit dataChange, but nothing.

    this is the code

    Qt Code:
    1. bool CustomItemDelegate::editorEvent(QEvent *event,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index)
    4. {
    5. const QSortFilterProxyModel* modelx =
    6. static_cast<const QSortFilterProxyModel*>(index.model());
    7.  
    8. QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)modelx->sourceModel())->widgetAt(index);
    9. ((WidgetBoxCategoryModel*)modelx->sourceModel())->refresh();
    10.  
    11. m_strName = widget.name();
    12. QRect buttonRect( option.rect);
    13. buttonRect.setWidth( 30);
    14.  
    15.  
    16. if(widget.getFunction() == QDesignerWidgetBoxInterface::Widget::Creator)
    17. {
    18. if( event->type() == QEvent::MouseButtonPress){
    19. }
    20. else if( event->type() == QEvent::MouseButtonRelease) {
    21.  
    22. if(m_pPrecedentPressedState != NULL && m_pPrecedentPressedState != &m_pressedState)
    23. *m_pPrecedentPressedState = QStyle::State_Raised;
    24.  
    25. widget.setName("luigi");//CHANGE THE MODEL !!!!!!!
    26.  
    27. m_pressedState = *widget.getState();
    28. if(m_pressedState == QStyle::State_Sunken )
    29. m_pressedState = QStyle::State_Raised ;
    30. else
    31. { m_pressedState = QStyle::State_Sunken;
    32. }
    33. m_pPrecedentPressedState = &m_pressedState;
    34. m_strPressedName = widget.name();
    35. }
    36. }
    37.  
    38. if( event->type() == QEvent::MouseButtonRelease) {
    39.  
    40. emit buttonClicked( index);
    41. emit pressDel(m_strName);
    42. }
    43. ((WidgetBoxCategoryModel*)modelx->sourceModel())->ChangeData();
    44. return true;
    45.  
    46. }
    To copy to clipboard, switch view to plain text mode 

    ((WidgetBoxCategoryModel*)modelx->sourceModel())->ChangeData();
    WidgetBoxCategoryModel is a custom model with into this function:

    Qt Code:
    1. void WidgetBoxCategoryModel::ChangeData()
    2. {
    3.  
    4. dataChanged(index(0,0),index(2,2));
    5. emit dataChanged(index(0,0),index(2,2));
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: datachange

    too many possibilities.

    Maybe your 'change the model' is never hit. Maybe your model isn't correct.

    maybe the fact that this line
    Qt Code:
    1. QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)modelx->sourceModel())->widgetAt(index);
    2. // widget is *new* object on the stack widgetAt returns by value? by reference?
    To copy to clipboard, switch view to plain text mode 
    makes a COPY is important.

    Who is to know?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: datachange

    I think Amleto's copy hypotheses is good.

    As an aside, all those unsafe casts make my eyes hurt, and they will eventually make you hurt too.
    Line 7 should be a qobject_cast<>() followed immediately by a check for success.
    You should qobject_cast<>() the source model to WidgetBoxCategoryModel* once only and also follow that with a check for success.

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

    Default Re: datachange

    I don't think a custom delegate should really ever access QDesignerWidgetBoxInterface which is only present when you're implementing a custom plugin for Qt Designer. Unless of course your custom delegate is only used within the Designer plugin.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.