Bj,
j'ai rencontré un prb qd j'utilise QGraphicsSceneHoverEvent.
je veux changer la curseur qd le curseur approche le contour d'un QGraphicsItem objet.
Voilà la code dan PolygonItem.cpp (qui hérite QGraphicsPolygonItem)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void PolygonItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
{
    ofstream myfile;
    myfile.open("hoverentre.txt");
    QPointF mousePos = QPointF(event->pos());
    QPointF ptl = this->boundingRect().topLeft();
    QPointF pbr = this->boundingRect().bottomRight();
    myfile << "ptl : (" << ptl.x() << "," << ptl.y() << ")" << endl;
    myfile << "pbr : (" << pbr.x() << "," << pbr.y() << ")" << endl;
    float width = this->boundingRect().width();
    float height = this->boundingRect().height();
    if( (mousePos.x() == ptl.x() && mousePos.y() == ptl.y())
        || (mousePos.x() == pbr.x() && mousePos.y() == pbr.y()) )
    {
        this->setCursor(Qt::SizeFDiagCursor);
        myfile << "mouse : (" << mousePos.x() << "," << mousePos.y() << ")" << endl;
    }
    else if((mousePos.x() == pbr.x() && mousePos.y() == ptl.y())
        || (mousePos.x() == ptl.x() && mousePos.y() == pbr.y()))
    {
        this->setCursor(Qt::SizeBDiagCursor);
        myfile << "mouse : (" << mousePos.x() << "," << mousePos.y() << ")" << endl;
    }
    else if((mousePos.x() == ptl.x() || mousePos.x() == pbr.x()))
    {
        this->setCursor(Qt::SizeHorCursor);
        myfile << "mouse : (" << mousePos.x() << "," << mousePos.y() << ")" << endl;
    }
    else if((mousePos.y() == ptl.y() || mousePos.y() == pbr.y()))
    {
        this->setCursor(Qt::SizeVerCursor);
        myfile << "mouse : (" << mousePos.x() << "," << mousePos.y() << ")" << endl;
    }
    myfile.close();
 
}
le résultat: qd on s'approche de gauche, de haut, ou de gauche en haut , ça peut marcher. mais dans les autres cas, ça peut pas marcher.
Je comprends pas pk..