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

}









share|improve this question




















  • 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 QWidget as 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















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

}









share|improve this question




















  • 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 QWidget as 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













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

}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 using QWidget as 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




    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 QWidget as 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












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.






share|improve this answer





















  • I'll try it! thanks
    – panc_fab
    Nov 8 at 12:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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
































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.






share|improve this answer





















  • I'll try it! thanks
    – panc_fab
    Nov 8 at 12:02















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.






share|improve this answer





















  • I'll try it! thanks
    – panc_fab
    Nov 8 at 12:02













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 11:10









CharonX

1,00418




1,00418












  • 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




I'll try it! thanks
– panc_fab
Nov 8 at 12:02


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































Popular posts from this blog

Landwehr

Reims

Schenkenzell