PDA

View Full Version : How to give Hover Effect for row in tableWidget.



jaya
5th October 2010, 08:01
How to give hover effect to row (Hover effect to multiple items of row.)

pavanbarot
21st February 2011, 13:19
Hi All i have same problem with qtablewidget. i have tried with item delegate my code as below:

void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{

QStyleOptionViewItem myOption = option;


painter->save();
QVariant value = index.data(Qt::DisplayRole);
QString text;

if( value.isValid())
{
text = value.toString();
}

if ( ( myOption.state & QStyle::State_MouseOver ) == QStyle::State_MouseOver )
{
qDebug() << "Hover on Column" << index.column();
qDebug() << "Mouse over on index Row:: " << index.row();
if(index.column() != 3)
{
myOption.palette.setColor(QPalette::Background, QColor(234,234,234));
painter->fillRect(myOption.rect, QColor( 234, 234, 234 ));

}
}
else
{
myOption.state &= ~QStyle::State_Selected;
painter->fillRect( option.rect, QColor( 247,247,247 ));
myOption.palette.setColor(QPalette::Background, QColor(247,247,247));
}

painter->drawText(myOption.rect, Qt::AlignLeft |Qt::AlignVCenter| Qt::TextWordWrap, text);
painter->restore();
}

please help me i have 10 cell and i got hover on only single cell. i want to draw fill color on all 10 cell. thanks in advance.

aamer4yu
24th February 2011, 20:01
Store some variable like isMouseOver in the model.
When mouse is over a particular cell, emit a signal to the parent / owner. From the slot, you must have what other 9 cells to update. From there , update the isMouseOver variable for the 9 cells.

In the delegate you can access the mouse over state as - index.data(MOUSE_OVER_ROLE); MOUS_OVER_ROLE is custom value.

Hope you get the idea :)