hello.
I have implemented a custom delegate for the extracted widgetbox of the qt designer.
The widgets in the widgetbox are buttons with an icon
My problem is that i must implement a special behaviour for the widgets.
in short when i press a widget i must first disable all the widget in the widgetbox without the selected widget then select the selected widget .
that is the problem:
the "paint" function that draw all the widgets is called only if a widged is dirty or has need to be drawed.
But I need to redraw all the widgets for each time i press a widget(that becomes the selected widget).
thanks.

this is the code
Qt Code:
  1. CustomItemDelegate::CustomItemDelegate(QObject *parent) :
  2. QItemDelegate(parent)
  3. {
  4. _state = QStyle::State_Enabled;
  5.  
  6. }
  7.  
  8.  
  9. void CustomItemDelegate::paint(QPainter *painter,
  10. const QStyleOptionViewItem &option,
  11. const QModelIndex &index) const
  12. {
  13. const QSortFilterProxyModel* model =
  14. static_cast<const QSortFilterProxyModel*>(index.model());
  15.  
  16. QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)model->sourceModel())->widgetAt(index);
  17.  
  18. QString strIcon = widget.iconName();
  19. QString text = widget.name();
  20. QRect rect = option.rect;
  21. QRect buttonRect( rect);
  22. buttonRect.setWidth( 30);
  23.  
  24. QIcon pq(strIcon);
  25.  
  26. button.icon = pq;
  27. button.iconSize = QSize(22, 22);
  28. button.palette = option.palette;
  29.  
  30. button.rect = buttonRect;
  31. //button.text = text;
  32. button.state = _state | QStyle::State_Enabled;
  33.  
  34. QApplication::style()->drawControl
  35. (QStyle::CE_PushButton, &button, painter);
  36. }
  37.  
  38. QSize CustomItemDelegate::sizeHint(const QStyleOptionViewItem &/*option*/,
  39. const QModelIndex &/*index*/) const
  40. {
  41. //hard coding size for test purpose,
  42. //actual size hint can be calculated from option param
  43. return QSize(800,30);
  44. }
  45.  
  46. bool CustomItemDelegate::editorEvent(QEvent *event,
  47. const QStyleOptionViewItem &option,
  48. const QModelIndex &index)
  49. {
  50. const QSortFilterProxyModel* modelx =
  51. static_cast<const QSortFilterProxyModel*>(index.model());
  52.  
  53. QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)modelx->sourceModel())->widgetAt(index);
  54.  
  55. m_strName = widget.name();
  56.  
  57. if( event->type() == QEvent::MouseButtonPress ||
  58. event->type() == QEvent::MouseButtonRelease ) {
  59. } else {
  60. //ignoring other mouse event and reseting button's state
  61. _state = QStyle::State_Raised;
  62. return true;
  63. }
  64.  
  65. QRect buttonRect( option.rect);
  66. //buttonRect.setY(option.rect.y()+ 35);
  67. //buttonRect.setHeight( 30);
  68. buttonRect.setWidth( 30);
  69. QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
  70. if( !buttonRect.contains( mouseEvent->pos()) ) {
  71. _state = QStyle::State_Raised;
  72. return true;
  73. }
  74.  
  75.  
  76. if(widget.getFunction() == QDesignerWidgetBoxInterface::Widget::Creator)
  77. {
  78. if(m_nOldName != widget.name() && m_nOldName != ""){
  79. _state = QStyle::State_Raised;
  80. return true;
  81. }
  82.  
  83. if( event->type() == QEvent::MouseButtonPress){
  84.  
  85. //if(_state == QStyle::State_Sunken)
  86. // _state = QStyle::State_Raised;
  87. //else
  88. // _state = QStyle::State_Sunken;
  89. }
  90. else if( event->type() == QEvent::MouseButtonRelease) {
  91. if(_state == QStyle::State_Sunken){
  92. _state = QStyle::State_Raised;
  93. }else{
  94. _state = QStyle::State_Sunken;
  95. m_nOldName = widget.name();
  96. }
  97.  
  98. }
  99.  
  100. }
  101.  
  102.  
  103. else if( event->type() == QEvent::MouseButtonPress) {
  104. _state = QStyle::State_Sunken;
  105. } else if( event->type() == QEvent::MouseButtonRelease) {
  106. _state = QStyle::State_Raised;
  107. emit buttonClicked( index);
  108. emit pressDel(m_strName);
  109. }
  110. return true;
  111. }
To copy to clipboard, switch view to plain text mode 

thanks.