Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The proxy in Qt TableView inherits the overriding paint function and does not move with the slider bar
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 398 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fanxinglanyu
    wrote on last edited by fanxinglanyu
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fanxinglanyu
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What exactly are you expecting ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fanxinglanyu
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Why don't you use a QStyledItemDelegate ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              F 1 Reply Last reply
              0
              • SGaistS SGaist

                Why don't you use a QStyledItemDelegate ?

                F Offline
                F Offline
                fanxinglanyu
                wrote on last edited by
                #7

                @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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved