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. How to hover an entire row on mouseover in a QTableView?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.3k 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.
  • Z Offline
    Z Offline
    zalan.szakolci
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mystery Keeper
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        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.

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        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