[Qt-interest] Qt/C++ working with graphicsview

Ross Driedger ross at earz.ca
Sun Jan 24 22:58:34 CET 2010


On 24-Jan-10, at 3:33 PM, qt-interest-request at trolltech.com wrote:

> Date: Sun, 24 Jan 2010 14:17:52 -0600
> From: "Stephen Deetz" <stephendeetz at chibardun.net>
> Subject: Re: [Qt-interest] Qt/C++ working with graphicsview (Ross
> 	Driedger)
> To: <qt-interest at trolltech.com>
> Message-ID: <000301ca9d32$4ecc2dd0$ec648970$@net>
> Content-Type: text/plain;	charset="us-ascii"
>
> Thanks, Ross.
>
> Re: Qt/C++ working with graphicsview (Ross Driedger)
>
>>> There is no point in deriving a new class unless you add
>>> something new to it.
>
> I agree, but the docs make it seem necessary to reimplement the paint
> method. I can paint otherwise, but really want to use QGraphicsView  
> Show to
> show the graphics items.

You don't need to re-implement unless you want it to do something  
other than what the base class does.

>
>>> I gather from your terminology that you have some Java experience.
>
> I programmed in Delphi for 10 years and C 10 years before that.  I  
> feel like
> 2 years old having to ask these simple questions. :)

Don't worry about how you 'look'.  C++ is an intimidating language  
that literally takes years to master.  For every line of good C++ out  
there there are many badly written lines.  I know this because I'm  
responsible for some of them before I tool the effort to really master  
the language.  In the corporate world I've come across too many whose  
knowledge  of the language did not come close to what they thought.   
You are asking questions which is a very good thing.

Regarding virtual functions, I seem to recall that Delphi is a late  
binding language so you won't come across the issue that this keyword  
addresses in C++ (I could be incorrect about Delphi).  In short, if  
you have a base class pointer or reference to an object and you want  
to call the derived version of a function on the base class, the  
function needs to be declared virtual in the base class.  You pay a  
price for this in the code is slightly slower and your object is  
bigger in memory.

But this is a subject that is drifting off-topic.

>
>>> Look up 'initiation lists' in a good C++ reference.
>
> Isn't this just short hand for the assignments (m_X = x, etc...) I'm  
> doing?
> I realized there was short hand, just didn't know the syntax off the  
> top of
> my head.

These lists are not short-hand.  They are required in the constructor  
to call the base constructor(s) and proper C++ form uses then to  
initialize class members.  It is not unusual for my constructors to  
have 20+ items in the lists for complex classes.

>
> I thought QGraphicsEllipseItem::QGraphicsEllipseItem( m_X, m_Y, m_W,  
> m_H,
> parent ); was the proper way to call the super class, but this won't  
> happen
> with just an initialization list, correct?

What you are doing in the constructor is creating another object that  
is destroyed when constructor is finished executing.  The only way you  
can call the base constructor is through a list as discussed above.

>
> In a Delphi constructor, one would call inherited() (super in java)
> immediately to make certain the inheritance chain is executed.  In C+ 
> +, the
> proper way is InheritedObject::InheritedObject, no?

In non constructor functions, this would be the way to do it.   
Constructors are a special case.  If you do not explicitly call the  
base constructor, the base class' default constructor is silently  
called.  In destructors, this is done automagically.

>
>>> Bounding Rect
>
> Sorry if my earlier question was unclear.
>
> My question: What does Qt use boundingRect for?

It returns the rect that describes the view real estate your item is  
occupying.  I use it to place music notation symbols in their proper  
locations wrt the ones before and after.  The paint engine uses the  
bounding rects to determine what needs to be redrawn.  It optimizes  
the rendering by redrawing only what is necessary.

All this said,. it might be helpful if you take a little time to get  
more familiar with C++ first.  Learning both the language and the Qt  
framework at the same time can be confusing.

Ross Driedger
ross_at_earz.ca




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100124/bd65e4df/attachment.html 


More information about the Qt-interest-old mailing list