Results 1 to 8 of 8

Thread: QGraphicsView wont show every item

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default QGraphicsView wont show every item

    I created a custom QGraphicsItem, subclassed it and everything. I run that with my program and it starts to hide my QGraphicsLineItems and my QGraphicsElipseItem. I am not sure why. I have narrowed it down to my customItem if anyone has any clue could you late me know. The code is below.
    Qt Code:
    1. #include "SearchArea.h"
    2.  
    3. SearchArea::SearchArea(double rangeExtent, double centerRange,
    4. double centerAzimuth, double azimuthExtent,
    5. QGraphicsScene *parent)
    6. : QGraphicsItem(0,parent)
    7. {
    8. radarCenterRange = rangeExtent;
    9. radarRangeExtent = centerRange;
    10. radarCenterAzimuth = centerAzimuth;
    11. radarAzimuthExtent = azimuthExtent;
    12. zoomValue = 1;
    13. cPoint = new QPoint();
    14. cPoint->setX(0);
    15. cPoint->setY(0);
    16. gPen = new QPen();
    17. gPen->setColor(Qt::green);
    18.  
    19. }
    20.  
    21. SearchArea::~SearchArea()
    22. {
    23.  
    24. }
    25. ////////////////////////////////////////////////////////////////////////
    26. void SearchArea::drawFence()
    27. {
    28. double rangeExtentZoom = radarRangeExtent/10 * zoomValue;
    29. double centerRangeZoom = radarCenterRange/10 * zoomValue;
    30. double rangeExtentZoomFarthest = centerRangeZoom + rangeExtentZoom/2;
    31. double rangeExtentZoomClosest = centerRangeZoom - rangeExtentZoom/2;
    32. double azimuthExtentLowest = radarCenterAzimuth - radarAzimuthExtent/2;
    33. double azimuthExtentHightest = radarCenterAzimuth + radarAzimuthExtent/2;
    34. QPoint startLowerLine, finishLowerLine, startUpperLine, finishUpperLine;
    35. gPainter->setPen(gPen->color());
    36.  
    37.  
    38. startLowerLine = GetArkPoint(radarCenterAzimuth, azimuthExtentLowest, rangeExtentZoomClosest);
    39. finishLowerLine = GetArkPoint(radarCenterAzimuth, azimuthExtentLowest, rangeExtentZoomFarthest);
    40. startUpperLine = GetArkPoint(radarCenterAzimuth, azimuthExtentHightest, rangeExtentZoomClosest);
    41. finishUpperLine = GetArkPoint(radarCenterAzimuth, azimuthExtentHightest, rangeExtentZoomFarthest);
    42.  
    43. double radius1 = sqrt(pow(finishLowerLine.x(),2)+pow(finishLowerLine.y(),2));
    44. double height1 = radius1*2;
    45.  
    46. gPainter->drawLine(startUpperLine, finishUpperLine);
    47. gPainter->drawLine(startLowerLine, finishLowerLine);
    48.  
    49. drawArcFence(startUpperLine,azimuthExtentLowest,radarAzimuthExtent);
    50. drawArcFence(finishUpperLine,azimuthExtentLowest,radarAzimuthExtent);
    51.  
    52.  
    53. gPainter->end();
    54.  
    55. }
    56. ////////////////////////////////////////////////////////////////////////
    57. void SearchArea::paint(QPainter *painter,
    58. const QStyleOptionGraphicsItem *option, QWidget *widget)
    59. {
    60. gPainter = painter;
    61. Q_UNUSED(option);
    62. Q_UNUSED(widget);
    63.  
    64. drawFence();
    65.  
    66. }
    67. ////////////////////////////////////////////////////////////////////////
    68. QPoint SearchArea::GetArkPoint(double centerAzimuth, double azimuth, double rangeExtent)
    69. {
    70. QPoint lowerArkPoint;
    71. lowerArkPoint.setY( (sin (azimuth*PI/180) * rangeExtent )*-1);
    72. lowerArkPoint.setX( (cos (azimuth*PI/180) * rangeExtent) );
    73. lowerArkPoint.setX( lowerArkPoint.x());
    74. lowerArkPoint.setY( lowerArkPoint.y());
    75.  
    76. return lowerArkPoint;
    77.  
    78. }
    79.  
    80. ////////////////////////////////////////////////////////////////////////
    81. void SearchArea::drawArcFence(QPoint point, double azimuth, double azimuthExtent)
    82. {
    83. gPainter->setPen(gPen->color());
    84. point.setX(point.x());
    85. point.setY(point.y());
    86. double radius = sqrt(pow(point.x(),2)+pow(point.y(),2));
    87. double height = radius*2;
    88. gPainter->drawArc(0-radius,0-radius,height,height,azimuth*16,azimuthExtent*16);
    89. }
    90. ////////////////////////////////////////////////////////////////////////
    91. QRectF SearchArea::boundingRect() const
    92. {
    93. return QRectF(0, 0,0, 0);
    94. }
    95. ////////////////////////////////////////////////////////////////////////
    96. void SearchArea::setPen(QPen * pen)
    97. {
    98. gPen = pen;
    99. }
    100. void SearchArea::setLocation(QPoint *centerPoint)
    101. {
    102. cPoint = centerPoint;
    103. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by abbapatris; 4th September 2007 at 18:26.

Similar Threads

  1. How to show progess in a QTreeView item ?
    By tanminh in forum Qt Programming
    Replies: 69
    Last Post: 3rd March 2008, 17:55
  2. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14
  3. QGraphicsView and item focus
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2007, 20:36
  4. Replies: 1
    Last Post: 19th April 2007, 22:23
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

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
  •  
Qt is a trademark of The Qt Company.