add hover/enter/leave capabilities to element in my QGraphicsScene
up vote
-1
down vote
favorite
basically I am trying to implement the Hover event on a QPointF, I need it to be clickable or at least being highlighted in some way.
What I've tried is to create a custom point starting by inheriting from QPointF, and then added hover,enter and leave methods as described in this tutorial, but it is not working. Also, the tut is based on generic QWidget and not specifically on points.
have you guys some hints/resources? google points me on a few tuts that are not useful, and the Qt page referred to HoverEvent is not tailored with examples.
thanks!
EDIT
More info needed. I am trying to draw a rectangle in a scene. The rectangle is of type QPolygonF and the scene is a QGraphicsScene type.
below the code block used to create a polygon from a list of points and its inclusion in the scene:
void
MyDialog::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPolygonF poly;
QPointF first;
for(int i = 0;i < points->size();i++)
{
double length = points->at(i).split(",").at(0).toDouble();
double rad = qDegreesToRadians( points->at(i).split(",").at(1).toDouble());
QPointF pt(length * qCos(rad),length * qSin(rad));
if(i == 0) first = pt;
poly << pt;
}
poly << first;
scene->addPolygon(poly,QPen(),QBrush(Qt::green,Qt::SolidPattern));
}
c++ qt hover point
|
show 1 more comment
up vote
-1
down vote
favorite
basically I am trying to implement the Hover event on a QPointF, I need it to be clickable or at least being highlighted in some way.
What I've tried is to create a custom point starting by inheriting from QPointF, and then added hover,enter and leave methods as described in this tutorial, but it is not working. Also, the tut is based on generic QWidget and not specifically on points.
have you guys some hints/resources? google points me on a few tuts that are not useful, and the Qt page referred to HoverEvent is not tailored with examples.
thanks!
EDIT
More info needed. I am trying to draw a rectangle in a scene. The rectangle is of type QPolygonF and the scene is a QGraphicsScene type.
below the code block used to create a polygon from a list of points and its inclusion in the scene:
void
MyDialog::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPolygonF poly;
QPointF first;
for(int i = 0;i < points->size();i++)
{
double length = points->at(i).split(",").at(0).toDouble();
double rad = qDegreesToRadians( points->at(i).split(",").at(1).toDouble());
QPointF pt(length * qCos(rad),length * qSin(rad));
if(i == 0) first = pt;
poly << pt;
}
poly << first;
scene->addPolygon(poly,QPen(),QBrush(Qt::green,Qt::SolidPattern));
}
c++ qt hover point
3
QPointF is a simple data class, not a widget. How could you even hover over a data-class, it is not represented in a GUI in any way. You should elaborate why you want to do this, as there is propably a different class (or at least approach) you should use for your use case
– Felix
Nov 8 at 10:17
@Felix sorry, you are right. I am a firmware developer, not used to work with OO and Qt, and I have no time to dig deeper. Actually, I was sure a QPoint was a graphical element put in a scene, but now I remember that a point is put into a scene in order to be "painted". Perhaps I'll have to think of working on the scene instead?
– panc_fab
Nov 8 at 10:27
1
I think you want to work usingQWidgetas it's most basic UI object
– Rhathin
Nov 8 at 10:30
1
Generally speaking, yes. You have to subclass or connect to whatever class actually represents the element to be drawn. This depends on how you draw the Scene. QWidgets, QML, QSceneGraph are some examples. Once we know which frontend is used we can find out how to archive it
– Felix
Nov 8 at 10:31
@Felix I'll edit the post with more infos.
– panc_fab
Nov 8 at 10:39
|
show 1 more comment
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
basically I am trying to implement the Hover event on a QPointF, I need it to be clickable or at least being highlighted in some way.
What I've tried is to create a custom point starting by inheriting from QPointF, and then added hover,enter and leave methods as described in this tutorial, but it is not working. Also, the tut is based on generic QWidget and not specifically on points.
have you guys some hints/resources? google points me on a few tuts that are not useful, and the Qt page referred to HoverEvent is not tailored with examples.
thanks!
EDIT
More info needed. I am trying to draw a rectangle in a scene. The rectangle is of type QPolygonF and the scene is a QGraphicsScene type.
below the code block used to create a polygon from a list of points and its inclusion in the scene:
void
MyDialog::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPolygonF poly;
QPointF first;
for(int i = 0;i < points->size();i++)
{
double length = points->at(i).split(",").at(0).toDouble();
double rad = qDegreesToRadians( points->at(i).split(",").at(1).toDouble());
QPointF pt(length * qCos(rad),length * qSin(rad));
if(i == 0) first = pt;
poly << pt;
}
poly << first;
scene->addPolygon(poly,QPen(),QBrush(Qt::green,Qt::SolidPattern));
}
c++ qt hover point
basically I am trying to implement the Hover event on a QPointF, I need it to be clickable or at least being highlighted in some way.
What I've tried is to create a custom point starting by inheriting from QPointF, and then added hover,enter and leave methods as described in this tutorial, but it is not working. Also, the tut is based on generic QWidget and not specifically on points.
have you guys some hints/resources? google points me on a few tuts that are not useful, and the Qt page referred to HoverEvent is not tailored with examples.
thanks!
EDIT
More info needed. I am trying to draw a rectangle in a scene. The rectangle is of type QPolygonF and the scene is a QGraphicsScene type.
below the code block used to create a polygon from a list of points and its inclusion in the scene:
void
MyDialog::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPolygonF poly;
QPointF first;
for(int i = 0;i < points->size();i++)
{
double length = points->at(i).split(",").at(0).toDouble();
double rad = qDegreesToRadians( points->at(i).split(",").at(1).toDouble());
QPointF pt(length * qCos(rad),length * qSin(rad));
if(i == 0) first = pt;
poly << pt;
}
poly << first;
scene->addPolygon(poly,QPen(),QBrush(Qt::green,Qt::SolidPattern));
}
c++ qt hover point
c++ qt hover point
edited Nov 8 at 12:01
asked Nov 8 at 10:07
panc_fab
1791317
1791317
3
QPointF is a simple data class, not a widget. How could you even hover over a data-class, it is not represented in a GUI in any way. You should elaborate why you want to do this, as there is propably a different class (or at least approach) you should use for your use case
– Felix
Nov 8 at 10:17
@Felix sorry, you are right. I am a firmware developer, not used to work with OO and Qt, and I have no time to dig deeper. Actually, I was sure a QPoint was a graphical element put in a scene, but now I remember that a point is put into a scene in order to be "painted". Perhaps I'll have to think of working on the scene instead?
– panc_fab
Nov 8 at 10:27
1
I think you want to work usingQWidgetas it's most basic UI object
– Rhathin
Nov 8 at 10:30
1
Generally speaking, yes. You have to subclass or connect to whatever class actually represents the element to be drawn. This depends on how you draw the Scene. QWidgets, QML, QSceneGraph are some examples. Once we know which frontend is used we can find out how to archive it
– Felix
Nov 8 at 10:31
@Felix I'll edit the post with more infos.
– panc_fab
Nov 8 at 10:39
|
show 1 more comment
3
QPointF is a simple data class, not a widget. How could you even hover over a data-class, it is not represented in a GUI in any way. You should elaborate why you want to do this, as there is propably a different class (or at least approach) you should use for your use case
– Felix
Nov 8 at 10:17
@Felix sorry, you are right. I am a firmware developer, not used to work with OO and Qt, and I have no time to dig deeper. Actually, I was sure a QPoint was a graphical element put in a scene, but now I remember that a point is put into a scene in order to be "painted". Perhaps I'll have to think of working on the scene instead?
– panc_fab
Nov 8 at 10:27
1
I think you want to work usingQWidgetas it's most basic UI object
– Rhathin
Nov 8 at 10:30
1
Generally speaking, yes. You have to subclass or connect to whatever class actually represents the element to be drawn. This depends on how you draw the Scene. QWidgets, QML, QSceneGraph are some examples. Once we know which frontend is used we can find out how to archive it
– Felix
Nov 8 at 10:31
@Felix I'll edit the post with more infos.
– panc_fab
Nov 8 at 10:39
3
3
QPointF is a simple data class, not a widget. How could you even hover over a data-class, it is not represented in a GUI in any way. You should elaborate why you want to do this, as there is propably a different class (or at least approach) you should use for your use case
– Felix
Nov 8 at 10:17
QPointF is a simple data class, not a widget. How could you even hover over a data-class, it is not represented in a GUI in any way. You should elaborate why you want to do this, as there is propably a different class (or at least approach) you should use for your use case
– Felix
Nov 8 at 10:17
@Felix sorry, you are right. I am a firmware developer, not used to work with OO and Qt, and I have no time to dig deeper. Actually, I was sure a QPoint was a graphical element put in a scene, but now I remember that a point is put into a scene in order to be "painted". Perhaps I'll have to think of working on the scene instead?
– panc_fab
Nov 8 at 10:27
@Felix sorry, you are right. I am a firmware developer, not used to work with OO and Qt, and I have no time to dig deeper. Actually, I was sure a QPoint was a graphical element put in a scene, but now I remember that a point is put into a scene in order to be "painted". Perhaps I'll have to think of working on the scene instead?
– panc_fab
Nov 8 at 10:27
1
1
I think you want to work using
QWidget as it's most basic UI object– Rhathin
Nov 8 at 10:30
I think you want to work using
QWidget as it's most basic UI object– Rhathin
Nov 8 at 10:30
1
1
Generally speaking, yes. You have to subclass or connect to whatever class actually represents the element to be drawn. This depends on how you draw the Scene. QWidgets, QML, QSceneGraph are some examples. Once we know which frontend is used we can find out how to archive it
– Felix
Nov 8 at 10:31
Generally speaking, yes. You have to subclass or connect to whatever class actually represents the element to be drawn. This depends on how you draw the Scene. QWidgets, QML, QSceneGraph are some examples. Once we know which frontend is used we can find out how to archive it
– Felix
Nov 8 at 10:31
@Felix I'll edit the post with more infos.
– panc_fab
Nov 8 at 10:39
@Felix I'll edit the post with more infos.
– panc_fab
Nov 8 at 10:39
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
QPointF is a data object; it does not provide any graphical representation whatsoever (and I would strongly advise you against inheriting from it to add one).
One way to possibly do it is to override the QGraphicsScene::mouseMoveEvent() and QGraphicsScene::mousePressEvent() functions, allowing you to listen-in on where the user moves and clicks, and reacting on that. There are probably better ways to do this, though - I've only needed to react on clicks (and not on hovers) so far, so my experiences are limited.
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
QPointF is a data object; it does not provide any graphical representation whatsoever (and I would strongly advise you against inheriting from it to add one).
One way to possibly do it is to override the QGraphicsScene::mouseMoveEvent() and QGraphicsScene::mousePressEvent() functions, allowing you to listen-in on where the user moves and clicks, and reacting on that. There are probably better ways to do this, though - I've only needed to react on clicks (and not on hovers) so far, so my experiences are limited.
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
add a comment |
up vote
1
down vote
QPointF is a data object; it does not provide any graphical representation whatsoever (and I would strongly advise you against inheriting from it to add one).
One way to possibly do it is to override the QGraphicsScene::mouseMoveEvent() and QGraphicsScene::mousePressEvent() functions, allowing you to listen-in on where the user moves and clicks, and reacting on that. There are probably better ways to do this, though - I've only needed to react on clicks (and not on hovers) so far, so my experiences are limited.
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
add a comment |
up vote
1
down vote
up vote
1
down vote
QPointF is a data object; it does not provide any graphical representation whatsoever (and I would strongly advise you against inheriting from it to add one).
One way to possibly do it is to override the QGraphicsScene::mouseMoveEvent() and QGraphicsScene::mousePressEvent() functions, allowing you to listen-in on where the user moves and clicks, and reacting on that. There are probably better ways to do this, though - I've only needed to react on clicks (and not on hovers) so far, so my experiences are limited.
QPointF is a data object; it does not provide any graphical representation whatsoever (and I would strongly advise you against inheriting from it to add one).
One way to possibly do it is to override the QGraphicsScene::mouseMoveEvent() and QGraphicsScene::mousePressEvent() functions, allowing you to listen-in on where the user moves and clicks, and reacting on that. There are probably better ways to do this, though - I've only needed to react on clicks (and not on hovers) so far, so my experiences are limited.
answered Nov 8 at 11:10
CharonX
1,00418
1,00418
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
add a comment |
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
I'll try it! thanks
– panc_fab
Nov 8 at 12:02
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205473%2fadd-hover-enter-leave-capabilities-to-element-in-my-qgraphicsscene%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
QPointF is a simple data class, not a widget. How could you even hover over a data-class, it is not represented in a GUI in any way. You should elaborate why you want to do this, as there is propably a different class (or at least approach) you should use for your use case
– Felix
Nov 8 at 10:17
@Felix sorry, you are right. I am a firmware developer, not used to work with OO and Qt, and I have no time to dig deeper. Actually, I was sure a QPoint was a graphical element put in a scene, but now I remember that a point is put into a scene in order to be "painted". Perhaps I'll have to think of working on the scene instead?
– panc_fab
Nov 8 at 10:27
1
I think you want to work using
QWidgetas it's most basic UI object– Rhathin
Nov 8 at 10:30
1
Generally speaking, yes. You have to subclass or connect to whatever class actually represents the element to be drawn. This depends on how you draw the Scene. QWidgets, QML, QSceneGraph are some examples. Once we know which frontend is used we can find out how to archive it
– Felix
Nov 8 at 10:31
@Felix I'll edit the post with more infos.
– panc_fab
Nov 8 at 10:39