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

Qt-jambi-interest Archive, November 2006
AW: AW: QGraphicsItem parent/child with clipping


Message 1 in thread

Hello,

first of all: thanks a lot for the help ;)

Just a couple of notes:
- WindowBlinds (www.stardock.com) doesn't work well with Qt-Jambi
  applications. Scrollbars are not rendered at all, for example.

- Overloading hide() in a QGraphicsItem derived class will result in
  a runtime Exception:

QtJambi: Exception pending in native code
com.trolltech.qt.QNonVirtualOverridingException: 
      Non-virtual function overridden: Function 'hide' in class
'net.steinke.qttest.QTTest$ResizeDecorator'
	at
com.trolltech.qt.gui.QGraphicsItem.__qt_QGraphicsItem_QGraphicsItem_QGraphic
sScene(Native Method)
	at com.trolltech.qt.gui.QGraphicsItem.<init>(QGraphicsItem.java:135)
	at com.trolltech.qt.gui.QGraphicsItem.<init>(QGraphicsItem.java:131)



Also, is there something like a "Thinking in Qt" document? I've 
written some Swing applications and I think I might try to do
my stuff to Swing-esque instead of Qt-esque (not sure if this made
any sense..)

What I'm trying to do is to create a user-resizable QGraphicsItem.
Right now I'm adding a "ResizeDecorator" to the scene, and make it
the child of the QGraphicsItem that should be resized. The decorator
has the same dimensions as it's parent item and draws drag-handles 
(just some rects at the corners an in the middle of each side).
The idea is that dragging the handles will resize the decorator,
and once the dragging stops I can calculate the resize factor and
apply it to the actual item.

Is this a good way to handle this? Or is there another method
that should be preferred?

Also, my decorator doesn't get the mouseMove events even after
it got a mousepress event. In the mousePressEvent method I've a
    if (scene().mouseGrabberItem() == this) {
        System.out.println("grabbed it!");
    }
which is printed to the console - so I should be the mouseGrabber
and get mouseEvents, right?


Best regards,
Lennart Steinke


> -----Ursprüngliche Nachricht-----
> Von: qt-jambi-interest-request@xxxxxxxxxxxxx
> Betreff: Re: AW: QGraphicsItem parent/child with clipping
> 
> 
> Lennart Steinke wrote:
> > But, now I have a new issue: whenever the scene is resized,
> > (say because an item was moved) the viewport changes it's
> > currently visible area slightly.
> > 
> > Is there a way to avoid it? I could set the size of the
> > scene to a really large value, but this seems a very dirty
> > way of dealing with this problem.
> 
> By default the view will try to view all the scene. You can 
> avoid this 
> by setting a scene rectangle:



best regards,
Gunnar


Message 2 in thread

Lennart Steinke wrote:
> Hello,
> 
> first of all: thanks a lot for the help ;)
> 
> Just a couple of notes:
> - WindowBlinds (www.stardock.com) doesn't work well with Qt-Jambi
>   applications. Scrollbars are not rendered at all, for example.

Hi Lennart,

We have received much requests for Qt in general running with 
WindowBlinds so this is unsupported from Trolltech.

> - Overloading hide() in a QGraphicsItem derived class will result in
>   a runtime Exception:
>
> QtJambi: Exception pending in native code
> com.trolltech.qt.QNonVirtualOverridingException: 
>       Non-virtual function overridden: Function 'hide' in class
> 'net.steinke.qttest.QTTest$ResizeDecorator'

What you see here is an unfortunate heritage from the Qt / C++ API. The 
function hide() is not virtual in C++ so the hide() function in your 
subclass will not be called when the object is hidden. So we decided to 
throw an exception instead indicate that this function should not be 
overridden.

> 
> Also, is there something like a "Thinking in Qt" document? I've 
> written some Swing applications and I think I might try to do
> my stuff to Swing-esque instead of Qt-esque (not sure if this made
> any sense..)

In general our documentation should be rather extensive, all classes 
have an overview chapter in the beginning of the java doc for instance 
outlining how the class is supposed to be used. In addition to that 
there are several overview docs if you go to:

http://doc.trolltech.com/qtjambi-1.0/com/trolltech/qt/qt-index.html

These are still in C++, but since they are conceptual docs rather than 
programming details this shouldn't be a big hurdle.

But what you are probably looking for is the Qt 4 book:

http://www.amazon.com/C%2B%2B-GUI-Programming-Qt-4/dp/0131872494/sr=8-1/qid=1164381019/ref=sr_1_1/105-4950248-8781202?ie=UTF8&s=books

It is also for C++, but again it focuses on the concepts and programming 
patterns so it should be quite helpful. Except for the template and 
buildsystem chapters of course ;-)

> What I'm trying to do is to create a user-resizable QGraphicsItem.
> Right now I'm adding a "ResizeDecorator" to the scene, and make it
> the child of the QGraphicsItem that should be resized. The decorator
> has the same dimensions as it's parent item and draws drag-handles 
> (just some rects at the corners an in the middle of each side).
> The idea is that dragging the handles will resize the decorator,
> and once the dragging stops I can calculate the resize factor and
> apply it to the actual item.
> 
> Is this a good way to handle this? Or is there another method
> that should be preferred?

This sounds like a sensible approach.

> Also, my decorator doesn't get the mouseMove events even after
> it got a mousepress event. In the mousePressEvent method I've a
>     if (scene().mouseGrabberItem() == this) {
>         System.out.println("grabbed it!");
>     }
> which is printed to the console - so I should be the mouseGrabber
> and get mouseEvents, right?

With the attached example the child gets all the events after the mouse 
press. You need to implement mousePressEvent() which will indicate to 
the scene that you accepted the event, otherwise it will go to the 
parent. Then you reimplement the mouseMoveEvent() to get the actual events.

best regards,
Gunnar
package com.trolltech.tests;
package com.trolltech.tests;

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

public class GraphicsChild extends QGraphicsItem {

    public void mousePressEvent(QGraphicsSceneMouseEvent event) {
    }

    @Override
    public void mouseMoveEvent(QGraphicsSceneMouseEvent event) {
        System.out.println("moved over " + name + ", " + event.pos().x() + ", " + event.pos().y());
    }

    public GraphicsChild(QGraphicsItemInterface parent, QGraphicsScene scene, String name) {
        super(parent, scene);
//        setAcceptsHoverEvents(true);
        this.name = name;
    }

    public QRectF boundingRect() {
        return new QRectF(0, 0, 100, 100);
    }
    
    public void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget) {
        painter.setBrush(new QBrush(QColor.red));
        painter.drawRect(boundingRect());
        painter.drawText(10, 10, name);
    }

    private String name;

    public static void main(String args[]) {
        QApplication.initialize(args);

        QGraphicsScene scene = new QGraphicsScene();

        GraphicsChild parent = new GraphicsChild(null, scene, "parent");
        GraphicsChild child = new GraphicsChild(parent, scene, "child");
        child.moveBy(50, 50);

        QGraphicsView view = new QGraphicsView(scene);
        view.show();

        QApplication.exec();
    }
}

Message 3 in thread

Gunnar Sletta wrote:

> We have received much requests for Qt in general running with 
> WindowBlinds so this is unsupported from Trolltech.

That should have been

"We have _not_ received ..."

Sorry for the confusion ;-)

-
Gunar