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.
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.
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
should I use QHoverEvent ?
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.
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:D
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!
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Use QEvent::Enter and QEvent::Leave.
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.
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Did you set the hover attribute on the view's viewport?
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Code:
view->setMouseTracking(true);
view->viewport()->setAttribute(Qt::WA_Hover,true);
{
qDebug()<<index.row();
if ( event
->type
() == QEvent::HoverEnter ) { qDebug
()<<
"enter...";
} // doesnt appear. (it does on mousemove)
return 0;
}
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.
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?
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
In the paint implementation :
using qdebug()<<option.state; i am able to "see" a QStyle::State_MouseOver State, but in the
implementation, i dont.. why is this?
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Probably because it's irrelevant there.
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 ?
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.
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::DecorationRole);
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)
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.
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!
2 Attachment(s)
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....