Results 1 to 3 of 3

Thread: How to give Hover Effect for row in tableWidget.

  1. #1
    Join Date
    Sep 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question How to give Hover Effect for row in tableWidget.

    How to give hover effect to row (Hover effect to multiple items of row.)

  2. #2
    Join Date
    Jul 2010
    Location
    Ahmedabad,Gujarat,India
    Posts
    25
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to give Hover Effect for row in tableWidget.

    Hi All i have same problem with qtablewidget. i have tried with item delegate my code as below:

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

    QStyleOptionViewItem myOption = option;


    painter->save();
    QVariant value = index.data(Qt:isplayRole);
    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.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to give Hover Effect for row in tableWidget.

    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

Similar Threads

  1. QProcess, how to give focus to the new process on Mac
    By simlab in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2010, 23:27
  2. who can give me a tutorials of write .pro file
    By fengtian.we in forum Qt Programming
    Replies: 5
    Last Post: 20th May 2007, 16:25
  3. how to write RS232,give me some advice?
    By hiuao in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2007, 08:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.