How can I get the Button drawed by QApplication::style()->drawControl or connect it's signal to a function?



  • @class CIconButtonDelegate : public QItemDelegate //QStyledItemDelegate for style to draw [by jzq]
    {
    public:
    CIconButtonDelegate(QWidget *parent =0 ): QItemDelegate(parent){}
    // painting
    void paint(QPainter *painter,
    const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    QStyleOptionButton button;
    button.rect = option.rect;//QRect(x,y,w,h);
    //button.text = "=^.^=";
    QIcon icon (index.data().toString());
    if(icon.isNull())
    icon =QIcon(CConfig::instance()->getImageDir() + "graphicitems/sf.png");
    button.icon = icon;
    button.state = QStyle::State_Enabled;

    QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter);
    }@

    what i want is custom Button item delegate for the view. when is clicked, it will trigger a dlg to choose a new png-file.
    and update button 's Icon as the new png.

    edit: My current workAround , override the editorEvent(...)

    @ bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    {
    if(event->type() == QEvent::MouseButtonPress){//单击
    QMouseEvent * e = (QMouseEvent *)event;
    if(e->button() == Qt::LeftButton){
    //... trigger the dlg for choose png file
    }
    @
    Thanks in advance!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.