[Qt-jambi-interest] Problems with QGraphicsItem::paint(...) after migration to QTJambi 4.4
Gunnar Sletta
gunnar at trolltech.com
Tue Aug 12 08:46:42 CEST 2008
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