Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

The proxy in Qt TableView inherits the overriding paint function and does not move with the slider bar



  • This is code:

    #ifndef DELETETOOLBUTTONDELEGATE_H
    #define DELETETOOLBUTTONDELEGATE_H
    
    #include    <QObject>
    #include    <QWidget>
    #include    <QItemDelegate>
    #include    <QMap>
    #include    <QStyleOptionButton>
    #include    <QModelIndex>
    
    class DeleteToolButtonDelegate :public QItemDelegate
    {
        Q_OBJECT
    public:
        DeleteToolButtonDelegate(QObject *parent=0);
    
    
        QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                              const QModelIndex &index) const Q_DECL_OVERRIDE;
    
        void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
    
        void setModelData(QWidget *editor, QAbstractItemModel *model,
                          const QModelIndex &index) const Q_DECL_OVERRIDE;
    
        void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
                                  const QModelIndex &index) const Q_DECL_OVERRIDE;
    
        void paint(QPainter *painter, const QStyleOptionViewItem &option,
            const QModelIndex & index ) const Q_DECL_OVERRIDE;
    private:
        QMap<QModelIndex, QStyleOptionButton*> m_btns;
    
    signals:
        void deleteCommodityData() const;
    };
    
    #endif // DELETETOOLBUTTONDELEGATE_H
    
    
    
    void DeleteToolButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    
    
        QStyleOptionButton* button = m_btns.value(index);
    
        if (!button) {
            button = new QStyleOptionButton();
           button->rect = option.rect.adjusted(0, 0, 0, 0);
            //button->rect =  QRect(option.rect.left(), option.rect.top(), option.rect.width(), option.rect.height());
            //button->text = "X";
            button->state |= QStyle::State_Enabled;
            button->icon = QIcon(":/Image/sc.png");
            button->iconSize = QSize(option.rect.width(), option.rect.height());
    
            (const_cast<DeleteToolButtonDelegate*>(this))->m_btns.insert(index, button);
        }
        painter->save();
    
        if (option.state & QStyle::State_Selected) {
            painter->fillRect(option.rect, option.palette.highlight());
    
        }
        painter->restore();
        QApplication::style()->drawControl(QStyle::CE_PushButton, button, painter);
    }
    
    
    

    alt text
    I need your help! Thanks!


  • Lifetime Qt Champion

    Hi,

    Please explain what you expect and what currently happens. Your issue is not obvious.

    On a side note, the thread title should be short and meaningful and the details go into the main text box.



  • This imagealt text
    Interface one and interface two are the same interface


  • Lifetime Qt Champion

    What exactly are you expecting ?



  • The problem is that the deleted icon doesn't move as the slider moves. I actually need to remove the icon to move along with the slider.


  • Lifetime Qt Champion

    Why don't you use a QStyledItemDelegate ?



  • @SGaist said in The proxy in Qt TableView inherits the overriding paint function and does not move with the slider bar:

    QStyledItemDelegate

    The effect is the same, the delete icon still doesn't follow the slider


  • Lifetime Qt Champion

    Can you provide a minimal compilable example that shows this behaviour ?


Log in to reply