[Qt-interest] showEvent in QGraphicsView - question about when to draw

franki franki at franki.eu.org
Fri Dec 10 12:34:07 CET 2010


Thursday 09 of December 2010 19:54:37 Mihail Naydenov napisał(a):
> It is hard for me to track you thoughts. What exactly are you trying to do.
> "During initialization of my class", what class?
> Why not draw on paint()? All will be initialized then.

Hello,

Maybe I start with explaining something about my app.
Application is based on QStackedWidget, and almost every page has 
QGrapvicsView stretched onto pages. Views are displaying plan of some 
building, each floor and so on. Plan itself is a jpg image with walls, doors, 
etc. Onto this plan I draw items like: windows, doors, radiators (for central 
heating) and so one. Some of this items are animated, eg. when You open the 
window, signal is sent to app through rs232 and window is opening itself.
Anyway, it's crucial for me to draw these items exacly at specific points.
The problem is: I run this application on 18" widescreen panel or on laptop, 
with different sizes and resolutions, so I can't set size of QGraphicsView to 
be constant (eg. in Qt Designer). The plan (I mean jpg image) is also scaled 
to fitt in the view. QGraphicsScene must be as big as QGraphicsView, without 
scrollbars. Because of this, sometimes I need to draw let's say window item 
at point 200px,250px and sometime at 300px,350px depending on the size of the 
screen. 
So I can think of two solutions of this problem.
1. I start drawing all items after I get signal from sublcassed QGraphicsView 
on showEvent, then I know size, I set scene to be almost size of 
QGraphicsView, and start drawing. However, now when I think about this it's 
still mess, because I would need to calculate where to paint items.
2. Second idea is to set scene before showEvent, little bigger than jpg with 
floor plan (without scaling it), place the jpg in the center of the scene, 
then draw items in their positions (which would be constant and always known 
because I know size of this jpg) and then on showEvent I should call 
fittInView with QRect set at the size of the previously created scene. I 
assume that every item, and background jpg, will be rescaled to fitt in view 
without scrollbars, but again I may be wrong, because this is really my first 
app, so I simply don't know, until I try. Moreover I was affraid that 
rescaling will make some of items little bit off their positions or for 
example fonts will not look nice after that. 

You said: "Why not draw on paint()" - You meant paint... what? paintEvent or 
something else? I honestly don't know what you meant by that.
Please someone advise me.

best regards
Marek

>
>
> ----- Original Message ----
>
> > From: franki <franki at franki.eu.org>
> > To: qt-interest <qt-interest at trolltech.com>
> > Sent: Thu, December 9, 2010 6:08:45 PM
> > Subject: [Qt-interest] showEvent in QGraphicsView - question about when
> > to
>
> draw
>
> > Hello,
> >
> > I had a problem determinig size of QGraphicsScene, and from what I  had
> > read so
> >
> > far, size of QGraphicsView should be determined in showEvent  because
> > before this event happend geometry has some bogus data.
> > So I did  it that way, but show event is comming late, far after class
> > itself had been  initialized. During initialization of my class, I used
> > to draw an items  inside scene, but now when showEvent is comming late
> > what should I do? eg.  Send a signal from inside subclassed
> > QGraphicsView, which triger some function in base class to start drawing
> > items?
> > Is that a right way, or  are there some other options?
> >
> > best  regards
> > Marek
> > _______________________________________________
> > Qt-interest  mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest






More information about the Qt-interest-old mailing list