[Qt-jambi-interest] Problems with QGraphicsItem::paint(...) after migration to QTJambi 4.4

Naumann, Nico Nico.Naumann at student.hpi.uni-potsdam.de
Tue Aug 12 14:10:56 CEST 2008


thank you for your response. 
I think that the scale factor in your scenario is correct because you call scale on the item itself. Since my scene contains thousands of QGraphicsItems, I can't call scale on each item after the view changes. In fact, what I do is to scale the view itself which, in QT4.3, resulted in scaled QGraphicsItems. Obviously this behaviour changed with QT4.4 since now you will see that after calling scale on the view, the items remain with an unchanged scale factor of 1.0. The question is, if this behaviour is by intention, or if it is a bug... 
By the way: is there any other convenient way to scale all items of a scene and determine their scale factor in their paint method afterwards?
 
Thank you,
Nico
 
Nico Naumann wrote:
> Hi,
> Today I migrated some Java sourcecode from version 4.3 to the current
> version 4.4 of QTJambi. After that, I am having trouble with the
> overloaded paint methods of QGraphicsItem which doesnt pass the correct
> scale factor of the item anymore.
>
> The following code (overridden paint method of a QGraphicsItems) always
> worked for me with version 4.3:
>
> @Override
> public void paint(QPainter painter, QStyleOptionGraphicsItem style,
> QWidget widget) {
>         if( style.levelOfDetail() >= Settings.GENERAL_LOD_NEAR ) {
>              // paint the item
>             // ...
>          }
>         else
>         {
>             // do something else
>         }
>     }
>
> After upgrading to 4.4, style.levelOfDetail() is always set to value
> 1.0, regardless of the scale factor of the scene. Also the matrix()
> function only returns the identity matrix.
>
> Is there any undocumented change in the API that I am not aware of? Or
> is there another, maybe a better way to determine the scale factor and
> to decide whether or not to draw an item?
>
> I'd really appreaciate your help, thank you
> Nico

Hi Nico,

I cannot reproduce this problem with the following example. Could you
see what you are doing differently and get back to me, and maybe we can
find out what's wrong.

best regards,
Gunnar

import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;

public class GraphicsView_LevelOfDetail {

     public static void main(String args[]) {

         QApplication.initialize(args);

         QGraphicsScene scene = new QGraphicsScene();
         QGraphicsView view = new QGraphicsView(scene);

         QGraphicsRectItem item = new QGraphicsRectItem(0, 0, 10, 10) {
                 public void paint(QPainter p, QStyleOptionGraphicsItem
item, QWidget widget) {
                     System.out.println("level of detail:" +
item.levelOfDetail());
                     super.paint(p, item, widget);
                 }
             };
         item.setBrush(new QBrush(QColor.red));
         item.setPen(new QPen(QColor.black));

         item.scale(2, 2);

         scene.addItem(item);


         view.show();

         QApplication.exec();

     }
}





More information about the Qt-jambi-interest mailing list