Results 1 to 2 of 2

Thread: Qpainter, drawPolygon, fillpath, bouding rect ....

  1. #1
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qpainter, drawPolygon, fillpath, bouding rect ....

    Qt Code:
    1. frameX::frameX(QGraphicsItem *parent)
    2. : position(parent)
    3. {
    4. setAcceptHoverEvents(true);
    5. this->StatusState=Status::deselected;
    6. this->rotCenter=0;
    7. this->fillQColor= (Qt::transparent);
    8. this->setFrameEnumXXType(type::Xarea);
    9. this->wide =128;
    10. this->high =128;
    11. }
    12.  
    13. QRectF frameX::boundingRect() const
    14. {
    15. return QRectF(0,0,this->wide,this->high);
    16. }
    17.  
    18. QPainterPath frameX::shape() const
    19. {
    20. path.addPolygon(polygonType);
    21. return path;
    22. }
    23.  
    24. void frameX::paint(QPainter *painter,
    25. const QStyleOptionGraphicsItem *option, QWidget *widget)
    26. {
    27. Q_UNUSED(option);
    28. Q_UNUSED(widget);
    29. QPen pen;
    30. QBrush brush;
    31. QPainterPath painterPath;
    32. pen.setWidth(4);
    33. pen.setColor(Qt::black);
    34. pen.setJoinStyle(Qt::RoundJoin);
    35. brush.setColor(this->fillQColor);
    36. brush.setStyle(Qt::SolidPattern);
    37. painterPath.addPolygon(this->polygonType);
    38. painter->setPen(pen);
    39. painter->drawPolygon(this->polygonType);
    40. painter->fillPath(painterPath,brush);
    41. }
    42.  
    43. void frameX::mousePressEvent(QGraphicsSceneMouseEvent *event){
    44. if(event->button() == Qt::RightButton){
    45. qDebug()<< "right button";
    46. }
    47. else if(event->button() == Qt::LeftButton){
    48. //qDebug()<< "right button";
    49. if (getFrameStatus()== Status::selected){
    50. setFrameStatus(Status::deselected);
    51. }
    52. else{
    53. setFrameStatus(Status::selected);
    54. }
    55. }
    56. else{
    57. qDebug()<< "wheel button";
    58. }
    59. }
    60.  
    61. void frameX::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
    62. {
    63. Q_UNUSED(event);
    64. /**hover enter event, place text here*/
    65. // setToolTip(QString(QObject::tr(("example"))));
    66. }
    67.  
    68. void frameX::setFrame(qreal xPos, qreal yPos, qreal rotCenter, type::frames frameType)
    69. {
    70. setFrameEnumXXType(frameType);
    71. this->rotCenter=rotCenter;
    72. this->xPos=xPos;
    73. this->yPos=yPos;
    74. this->centerX = this->wide/2;
    75. this->centerY = this->high/2;
    76. setPos(this->xPos-(this->centerX),this->yPos-(this->centerY));
    77. this->transform.translate(this->centerX,this->centerY);
    78. this->transform.rotate(this->rotCenter);
    79. this->transform.translate(-(this->centerX),-(this->centerY));
    80. setTransform(this->transform);
    81. }
    82.  
    83. void frameX::setFrameStatus(Status::frameState myFrameState)
    84. {
    85. switch(myFrameState)
    86. {
    87. case Status::selected:
    88. this->StatusState = Status::selected;
    89. qDebug() << "umbrella selected";
    90. this->fillQColor = (QColor(0,0,255,70));
    91. break;
    92. case Status::approved:
    93. this->StatusState = Status::approved;
    94. qDebug() << "selection approved";
    95. this->fillQColor = (QColor(0,255,0,70));
    96. break;
    97. case Status::deselected:
    98. this->StatusState = Status::deselected;
    99. qDebug() << "umbrella deselected";
    100. this->fillQColor = (Qt::transparent);
    101. break;
    102. default:
    103. qDebug() << "requested fill color" << myFrameState << "not avaliable";
    104. break;
    105. }
    106. update();
    107. }
    108.  
    109. int frameX::getFrameStatus() const
    110. {
    111. return this->StatusState;
    112. }
    To copy to clipboard, switch view to plain text mode 

    if the inside of the polyon is clicked it turns blue otherwise transparent.
    1.png
    But everytime if i just move over with the cursor, the painter paints the bounding rect
    white -> the green outline which is painted in a other class is overpainted.
    2.png
    What am i doing wrong......
    Last edited by Speerfish; 13th February 2014 at 13:19.

  2. #2
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter, drawPolygon, fillpath, bouding rect ....

    found the problem, actually it is not a problem, just the way relalizes what has or will be updated.
    Changed the properties that one change in the child object, letÅ› all other itmes per default also be redrawn....

Similar Threads

  1. Replies: 2
    Last Post: 26th December 2012, 01:03
  2. QPainter - fill rect with gradient
    By szisziszilvi in forum Newbie
    Replies: 1
    Last Post: 17th January 2011, 13:38
  3. Some problem with painter's fillpath() method
    By salmanmanekia in forum Qt Programming
    Replies: 8
    Last Post: 30th June 2008, 13:31
  4. drawPolygon() problem
    By WEM in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2008, 00:46
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.