-
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....
-
1 Attachment(s)
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
in my_model::data I added a:
Code:
if(role== Qt::EditRole ) {
return QString(index.
data(0).
toString());
}
since I read on http://wiki.qtcentre.org/index.php?t...tractItemModel
that Qt::EditRole returns a string, and now upon doubleclick the values "stay" in the cell.
But the story isnt over, I still dont understand how to use QSqlTableModel 's delegates on my_model too :(
(i have a datetime type in mysql which automagically has a spinbox editor in QSqlTableModel )
Someone should further edit the wiki article with examples of the functions :)
-
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
bump.
I still havent solved the last issue... :crying::crying::(
-
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Quote:
Originally Posted by
georgep
It returns a variant. The default delegate interprets it as a string later on. So you can return an int from this role and it will be displayed as a textual representation of the integer.
Quote:
But the story isnt over, I still dont understand how to use QSqlTableModel 's delegates on my_model too :(
(i have a datetime type in mysql which automagically has a spinbox editor in QSqlTableModel )
I don't understand the problem. What is it exactly that you don't know?
Quote:
Someone should further edit the wiki article with examples of the functions :)
Hmm... why don't you do it?
-
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Quote:
Originally Posted by
wysota
It returns a variant. The default delegate interprets it as a string later on. So you can return an int from this role and it will be displayed as a textual representation of the integer.
I don't understand the problem. What is it exactly that you don't know?
it might be simple, but I dont understand how to get the spinbox delegate in the datetime column of the database (and not in others)[see pic]. I searched for the code in
src\sql\models\qsqltablemodel.cpp but couldnt manage to find anything...
Quote:
Originally Posted by
wysota
Hmm... why don't you do it?
Because im very new to Qt, and not very experienced in cpp either so there is a significant chance i would write something stupid.
-
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Quote:
Originally Posted by
georgep
it might be simple, but I dont understand how to get the spinbox delegate in the datetime column of the database (and not in others)[see pic]. I searched for the code in
src\sql\models\qsqltablemodel.cpp but couldnt manage to find anything...
Because it's nothing related to the model. You need to provide your own delegate - subclass one of the existing classes and reimplement QAbstractItemDelegate::createEditor() to return a spinbox for the appropriate column or datatype.
Quote:
Because im very new to Qt, and not very experienced in cpp either so there is a significant chance i would write something stupid.
So please restrain yourself from such statements. It's either writing examples at the wiki or answering questions here. The time and will of people willing to help is limited -- don't reduce their motivation even more, please.
-
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Quote:
Originally Posted by
wysota
So please restrain yourself from such statements. It's either writing examples at the wiki or answering questions here. The time and will of people willing to help is limited -- don't reduce their motivation even more, please.
Thanks for the suggestion, i will reimplement a delegate class.
What statements :confused: ??? I think you might have misunderstood me (my fault probably), I was merely speaking about miself, and i never commanded anyone anything...:confused:
cheers
-
Re: How do I obtain mouse hover/popup functionality in a Qtableview?
Quote:
Originally Posted by
georgep
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....
How did you achieved this... I am trying to do the same but no luck. any hint or advice?