Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: How do I obtain mouse hover/popup functionality in a Qtableview?

  1. #1
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question How do I obtain mouse hover/popup functionality in a Qtableview?

    Hi,

    i am using a Qtableview to display data in table form, what classes do I need to use/subclass so that when I hover the mouse over an item I can display some image.
    Basically i want to see the picture in decorationRole, only bigger, so hovering over the cell with the mouse would be perfect.

    Does QWidget::mouseMoveEvent ( QMouseEvent * event ) help me in any way?

    thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    QAbstractItemDelegate::editorEvent() and enabling WA_Hover attribute for the viewport of the view are the way to go.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    should I use QHoverEvent ?
    Last edited by georgep; 18th March 2009 at 23:34.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Yes, viewport

    Yes, it will work like this - you have to react on enterEvent and leaveEvent probably.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    haha, sorry for the rewrite, i just had figured it out and didnt see your reply

    im using QEvent::Hoverenter but apparently its behaving like HoverMove...ie: if I move the mouse in the cell.. it still "fires"


    thanks for the replys!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Use QEvent::Enter and QEvent::Leave.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Wink Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    I set the delegate on a column (view->setItemDelegateForColumn(1, new BoxDelegate(this) ); ) ...but somehow when entering the mouse over the column I dont get Enter of leave, i get MouseMove... dont understand why yet....



    ps: someone should have told me to RTFM the "Events and Event Filters" article in Assistant.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Did you set the hover attribute on the view's viewport?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Qt Code:
    1. view->setMouseTracking(true);
    2. view->viewport()->setAttribute(Qt::WA_Hover,true);
    3.  
    4.  
    5.  
    6. bool BoxDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
    7. {
    8.  
    9. qDebug()<<index.row();
    10. if ( event->type() == QEvent::HoverEnter ) { qDebug()<<"enter..."; } // doesnt appear. (it does on mousemove)
    11.  
    12. return 0;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 19th March 2009 at 09:15. Reason: missing [code] tags

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    If you want to enable mouse tracking, you have to do it on the viewport as well (then you'll receive enter and leave events). But it's not required. After taking a closer look on a working example I think you don't need to react on QEvent::Enter or QEvent::Leave. Just reimplement paint() and check whether the mouse is currently hovering over your item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    I tried view->viewport()->setMouseTracking(true); but I still dont get any enter or Leave
    About reimplementing paint, is there any example somewhere that shows how to see if mouse is over something?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    In the paint implementation :
    Qt Code:
    1. void BoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    To copy to clipboard, switch view to plain text mode 
    using qdebug()<<option.state; i am able to "see" a QStyle::State_MouseOver State, but in the

    Qt Code:
    1. bool BoxDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
    To copy to clipboard, switch view to plain text mode 
    implementation, i dont.. why is this?

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Probably because it's irrelevant there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    just one small unrelated question
    Can i show images (.jpg,.gif) that are stored as BLOB in mysql directly in a qtableview ?

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Depends what you mean by "directly". You have to read them from the database and create pixmaps out of them. Once you do that, you can show the images in a widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    I hope i get lucky and someone tells me where im screwing up so I dont have to open yet another thread...


    I have a
    model = new QSqlRelationalTableModel(this);
    which gets data from mysql. I also have a myView subclass from QTableView.


    If I :
    model->setData(model->index( 1 ,1) , QPixmap(":/images/new.png"), Qt:ecorationRole);
    I would expect that the decoration role icon would become visible in the tableview, but it doesnt ( What do I have to do to get the icon to show ? Am i forced to subclass the model ? Isnt there any other way ?
    I tryed to reimplment paint() but with no luck ....
    (PS: the pixmap and resource exist/work)

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    SQL models don't support decorationRole out of the box. You have to subclass the model and introduce support for it by reimplementing data(), setData() and adding some container for storing the icons.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    Awwww man, thanks! Ive been trying for hours
    That phrase should be in the documentation :< Thx again!

  20. #20
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: How do I obtain mouse hover/popup functionality in a Qtableview?

    I have subclassed QSqlTableModel in order to have a DecorationRole, no problem there.

    Problem is that when editing (double click on a cell) with My_model the cell turns blank and Remains blank after the cell looses focus.. (of course i dont type anything).
    With QSqlTableModel when i click a cell the contents remain there...
    I get the same behavior with or without my own setData(..) .
    Tried having return QSqlTableModel::setData(index,value,role); in my setdata() but no success....
    Whats the trick? I am speculating that i am loosing the delegates used by qsqltablemodel....
    Attached Images Attached Images
    Last edited by georgep; 19th April 2009 at 22:50.

Tags for this Thread

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.