Results 1 to 8 of 8

Thread: QGraphicsView wont show every item

  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.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView wont show every item

    OK.
    The first error I see is that you return an empty bounding rect.
    The bounding rect of a QGraphicsItem is used by the view to know what/where to render.

    This problem does not seem to be the logical reason for the problem in your post, but it is still an error.

    Could you correct that and post back? Or at least say why do you return an empty bounding rect.


    Other than that, your graphics item might cover everything else. This could be because of all the computations you do. Maybe some of them are wrong and you get very big values.

    But first try to correct the bounding rect.

    Regards

  3. #3
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: QGraphicsView wont show every item

    The bounding issue is due to me playing around with it to get it to work. I forgot to change it back to its original size. But it was at the correct size and still gave the same results.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView wont show every item

    OK. Then could you paste a set of values that you pass to the item's constructor?


    Regards

  5. #5
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: QGraphicsView wont show every item

    SearchArea * radarItem = new SearchArea(600, 1000, 70, 120, this);

    "this" is the scene that I am using.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView wont show every item

    The values seem OK. At least the ones I've computed.
    They biggest dimension is not bigger than ~300.

    So, what if you draw a border around your item? Draw a rect exactly on the bounding box. This way you will see clearly how much it expands.

    BTW, what's with that QGraphicsItem constructor with two parameters?

    Regards

  7. #7
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: QGraphicsView wont show every item

    the two variables in the constructor were copied from someone else's code. I am just learning so I tried what they put.

  8. #8
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: QGraphicsView wont show every item

    I got all the objects to show up correctly. I just removed the line that says gPainter->end(). But I still have a problem refreshing after scrolling the graphics view so the item is no longer on the screen.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.