How i can draw a rect 22x22 to make clickabel && emit a signal to parent QWidget
like a ....

QPixmap pix(22, 22);
pix.fill(normalcolor); ... ?


I tested to put in direct a QToolButton but loop to infinite..... and is a setIndexWidget....




Qt Code:
  1. void BaseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  2. {
  3. /////////qDebug() << "### index-column " << index.column();
  4.  
  5. if (index.column() == 0) {
  6. /* not on edit only flags |= Qt::ItemIsSelectable; */
  7. QString numer = index.model()->data(index, Qt::DisplayRole).toString();
  8. QString text = QString("(%1)").arg(numer);
  9. QToolButton * button1 = new QToolButton(tas);
  10. button1->setText(text);
  11. tas->setIndexWidget(index,button1);
  12. } else if (index.column() == 1) {
  13. /* not on edit only flags |= Qt::ItemIsSelectable; */
  14. QString coder = index.model()->data(index, Qt::DisplayRole).toString();
  15. QStyleOptionViewItem myOption = option;
  16. myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
  17. myOption.palette.setColor( QPalette::Text , Qt::red );
  18. drawDisplay(painter, myOption, myOption.rect,coder);
  19. drawFocus(painter, myOption, myOption.rect);
  20.  
  21. }
  22. ...............
  23.  
  24.  
  25. }
  26.  
  27. /* header */
  28.  
  29. class BaseDelegate : public QSqlRelationalDelegate
  30. {
  31. Q_OBJECT
  32.  
  33. public:
  34. BaseDelegate( QTableView *ta , QObject *parent );
  35. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  36. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  37. void setEditorData(QWidget *editor, const QModelIndex &index) const;
  38. void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
  39. private slots:
  40. private:
  41. QTableView *tas;
  42.  
  43. };
To copy to clipboard, switch view to plain text mode