Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Button Delegate Problem in TableView

$
0
0
Hi, I have subclass a class from QItemDelegate to have a button in tableView. I’ve done this But there is problem with mouse hover in this button. Other buttons as you know get focused and highlighted when mouse is hovered But in this case nothing happens when mouse enters the button. How can i do this?? I think somethings have to added into editorEvent method, but in this method i haven’t access to those buttons which have painted in paint method… Any suggestion? Paint Method: void TButtonDelegate::paint(QPainter *painter,                             const QStyleOptionViewItem &option,                             const QModelIndex &index) const {     Q_UNUSED(index);       QStyleOptionButton button;       // getting the rect of the cell     QRect r = option.rect;       int x,y,w,h;       // The x coordinate of the cell     x = r.left() + r.width() - 30;       y = r.top();       w = 30;       h = r.height();       button.rect = QRect(x,y,w,h);       button.text = "<=";       button.state = QStyle::State_Enabled;       QApplication::style()->drawControl(QStyle::CE_PushButton,                                        &button,painter);       painter->drawText(QRect(r.left() + 5,r.top(),r.width() - w,r.height()),                       (Qt::AlignVCenter | Qt::AlignLeft),                       index.data(Qt::DisplayRole).toString()); } EditorEvent Method bool TButtonDelegate::editorEvent(QEvent *event,                                   QAbstractItemModel *model,                                   const QStyleOptionViewItem &option,                                   const QModelIndex &index) {     if( event->type() == QEvent::MouseButtonRelease )     {         QMouseEvent * e = (QMouseEvent *)event;           int clickX = e->x();           int clickY = e->y();           QRect r = option.rect;//getting the rect of the cell           int x,y,w,h;           x = r.left() + r.width() - 30;//the X coordinate           y = r.top();//the Y coordinate           w = 30;//button width           h = 30;//button height           if( clickX > x && clickX < x + w )             if( clickY > y && clickY < y + h )             {                 emit cellButtonClicked(index);                 return true;             }     }       return QItemDelegate::editorEvent(event,model,option,index); }

Viewing all articles
Browse latest Browse all 18427

Trending Articles