How to hover an entire row on mouseover in a QTableView?



  • I subclassed QTableView, QAbstractTableModel, and QItemDelegate. I am able to hover a single cell on mouse over:

    @
    void SchedulerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    if(option.showDecorationSelected &&(option.state & QStyle::State_Selected))
    {
    QColor color(255,255,130,100);
    QColor colorEnd(255,255,50,150);
    QLinearGradient gradient(option.rect.topLeft(),option.rect.bottomRight());
    gradient.setColorAt(0,color);
    gradient.setColorAt(1,colorEnd);
    QBrush brush(gradient);
    painter->fillRect(option.rect,brush);
    }
    }

    @

    ... but I cannot figure out, how to hover an entire row. Can Someone help me with sample codes?



  • By "hovering" do you mean "highlighting"? Make a variable in the model that stores the row number under the mouse pointer and a method to set it. Set it every time mouse moves over the view. Make the model supply BackgroundRole data based on that variable. Also make it emit signal for the complete data update to the view. And be ready for constant view repaints.



  • I don't think there is such an implementation... but you can select entire row with setSelectionBehavior(QAbstractItemView::SelectRows)

    You can do a simple "hack" by installing an eventFilter() to QTableView to capture hover events then get the row/index at mouse position.


Log in to reply
 

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