Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, July 2007
help regarding QCanvas scrolling


Message 1 in thread


Note: forwarded message attached.
 
---------------------------------
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
--- Begin Message ---
Hi 

 I have a custom class inherited from  QCanvasPolygonalitem.I am using this class to draw a triangular shaped polygon inside a QCanvas having scroll bars.My polygon can rotate as well as move inside the canvas.The problem i am facing is that if my polygon moves inside the area currently visible on the canvas i can see polygon moving but if i scroll the canvas view even a little or my polygon moves to area not initially visible on the screen (as i have a very big bitmap) my polygon disappears and i dont see the polygon again.The code works perfect till the time polygon is inside the area initially visible on the canvas but not after i scroll.Please help me in this  regard to give me idea what can be the cause of problem.Thanks.

       
---------------------------------
Boardwalk for $500? In 2007? Ha! 
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
#include <qcanvas.h>
#include <qpainter.h> 
#include <qmessagebox.h>

///********************This class displays UGV polygon during Simulation**************************** 

class MyCanvasItem : public QCanvasPolygonalItem
{
public:
  MyCanvasItem( int width, int height, QCanvas *c ) : QCanvasPolygonalItem( c )
  {
    m_width = width;
    m_height = height;
 angle=0;
  
  }
  
  ~MyCanvasItem()
  {
    hide(); // Required to avoid segfault - see docs
  
}
  
  QPointArray areaPoints() const
  {
    
    
    QPointArray points( 3 );
    points.setPoint( 0,-m_width,-m_width );
    points.setPoint( 1,-m_width,m_width );
    points.setPoint( 2,2*m_width, 0 );


  return points;
  
  }
 
 
  void calldraw()

  {
 
 
   
update();

  }
public:
 
///This function is called eachtime we are changing the position or the angle of the car by canvas->update()	
	
	void drawShape( QPainter &p )
  {
  
    //painter=p;
    p.save();
    QWMatrix t,t1,r; 
   

   
	
 t.translate(x() ,y()); 
 t.rotate(angle); 
 p.setWorldMatrix(t); 
  p.drawPolygon( areaPoints()); 
    invalidate();
                    // draw car body
//	painter_rect=p.window();
	
 p.restore();
    update();
  }
 	
	 QRect areaRec()
	{

       

	return painter_rect;
	}

	

public:
	int angle;
     QPainter painter;  

private:
  int m_width;
  int m_height;
	 QRect painter_rect;
   
}; 


--- End Message ---

--- End Message ---