Results 1 to 20 of 27

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  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?

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  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?

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  7. #7
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  9. #9
    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 ?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  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 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)

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


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
  •  
Qt is a trademark of The Qt Company.