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
bool CustomItemDelegate
::editorEvent(QEvent *event,
{
((WidgetBoxCategoryModel*)modelx->sourceModel())->refresh();
m_strName = widget.name();
QRect buttonRect
( option.
rect);
buttonRect.setWidth( 30);
{
if( event
->type
() == QEvent::MouseButtonPress){ }
else if( event
->type
() == QEvent::MouseButtonRelease) {
if(m_pPrecedentPressedState != NULL && m_pPrecedentPressedState != &m_pressedState)
*m_pPrecedentPressedState
= QStyle::State_Raised;
widget.setName("luigi");//CHANGE THE MODEL !!!!!!!
m_pressedState = *widget.getState();
if(m_pressedState
== QStyle::State_Sunken ) m_pressedState
= QStyle::State_Raised ;
else
{ m_pressedState
= QStyle::State_Sunken;
}
m_pPrecedentPressedState = &m_pressedState;
m_strPressedName = widget.name();
}
}
if( event
->type
() == QEvent::MouseButtonRelease) {
emit buttonClicked( index);
emit pressDel(m_strName);
}
((WidgetBoxCategoryModel*)modelx->sourceModel())->ChangeData();
return true;
}
bool CustomItemDelegate::editorEvent(QEvent *event,
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
const QSortFilterProxyModel* modelx =
static_cast<const QSortFilterProxyModel*>(index.model());
QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)modelx->sourceModel())->widgetAt(index);
((WidgetBoxCategoryModel*)modelx->sourceModel())->refresh();
m_strName = widget.name();
QRect buttonRect( option.rect);
buttonRect.setWidth( 30);
if(widget.getFunction() == QDesignerWidgetBoxInterface::Widget::Creator)
{
if( event->type() == QEvent::MouseButtonPress){
}
else if( event->type() == QEvent::MouseButtonRelease) {
if(m_pPrecedentPressedState != NULL && m_pPrecedentPressedState != &m_pressedState)
*m_pPrecedentPressedState = QStyle::State_Raised;
widget.setName("luigi");//CHANGE THE MODEL !!!!!!!
m_pressedState = *widget.getState();
if(m_pressedState == QStyle::State_Sunken )
m_pressedState = QStyle::State_Raised ;
else
{ m_pressedState = QStyle::State_Sunken;
}
m_pPrecedentPressedState = &m_pressedState;
m_strPressedName = widget.name();
}
}
if( event->type() == QEvent::MouseButtonRelease) {
emit buttonClicked( index);
emit pressDel(m_strName);
}
((WidgetBoxCategoryModel*)modelx->sourceModel())->ChangeData();
return true;
}
To copy to clipboard, switch view to plain text mode
((WidgetBoxCategoryModel*)modelx->sourceModel())->ChangeData();
WidgetBoxCategoryModel is a custom model with into this function:
void WidgetBoxCategoryModel::ChangeData()
{
dataChanged(index(0,0),index(2,2));
emit dataChanged(index(0,0),index(2,2));
}
void WidgetBoxCategoryModel::ChangeData()
{
dataChanged(index(0,0),index(2,2));
emit dataChanged(index(0,0),index(2,2));
}
To copy to clipboard, switch view to plain text mode
Bookmarks