Qt-interest Archive, March 2008
QGraphicsItem with fixed size
Message 1 in thread
Hi.
I need to create a QGraphics item with fixed size also when I scale the scene with QGraphcsScene::scale().
So I have create a simple sqared object and I have implemented this methods:
MyMarker::MyMaker()
{
hw = 5.0;
setFlag(QGraphicsItem::ItemIsMovable);
}
QRectF MyMarker::boundingRect() const
{
return QRectF(-hw, -hw, hw * 2, hw * 2);
}
void MyMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /* = 0 */)
{
double nhw = 5.0 / option->levelOfDetail;
if(nhw != hw)
{
hw = nhw;
prepareGeometryChange();
}
painter->drawRect(QRectF(-hw, -hw, hw * 2, hw * 2));
}
In this way my sqare have always size of 5 pixel.
The problem is that if I try to remove the item from the scene with QGraphicsScene::removeItem() a strange thing appens. The item is still drawn in the scene, but it's no longer movable.
Moreover, if I also delete the item, the program crashes.
I don't know if there is some bug in my code or in Qt. Anyway, if someone have another idea to implement an object with fixed size, I'll appreciate. Scale every items of this type when I scale the scene doesn't seem to be a good and smart solution...
Thanks.
Fabio.
--
[ signature omitted ]
Message 2 in thread
Hi,
On Mon, 17 Mar 2008 17:20:54 +0100, "fabiodago@xxxxxxxxx" <fabiodago@xxxxxxxxx> wrote:
> Hi.
>
> I need to create a QGraphics item with fixed size also when I scale the
> scene with QGraphcsScene::scale().
>
> So I have create a simple sqared object and I have implemented this
> methods:
>
> MyMarker::MyMaker()
> {
> hw = 5.0;
> setFlag(QGraphicsItem::ItemIsMovable);
> }
>
> QRectF MyMarker::boundingRect() const
> {
> return QRectF(-hw, -hw, hw * 2, hw * 2);
> }
>
> void MyMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem
> *option, QWidget *widget /* = 0 */)
> {
> double nhw = 5.0 / option->levelOfDetail;
> if(nhw != hw)
> {
> hw = nhw;
> prepareGeometryChange();
> }
> painter->drawRect(QRectF(-hw, -hw, hw * 2, hw * 2));
> }
>
> In this way my sqare have always size of 5 pixel.
>
> The problem is that if I try to remove the item from the scene with
> QGraphicsScene::removeItem() a strange thing appens. The item is still
> drawn in the scene, but it's no longer movable.
> Moreover, if I also delete the item, the program crashes.
>
> I don't know if there is some bug in my code or in Qt. Anyway, if someone
> have another idea to implement an object with fixed size, I'll appreciate.
> Scale every items of this type when I scale the scene doesn't seem to be a
> good and smart solution...
Have a look at QGraphicsItem::ItemIgnoresTransformations ( using QGraphicsItem::setFlags() ).
> Thanks.
>
> Fabio.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 3 in thread
On Mon, 2008-03-17 at 21:05, Christopher Rasch-Olsen Raa wrote:
On Mon, 17 Mar 2008 17:20:54 +0100, "fabiodago@xxxxxxxxx"
<fabiodago@xxxxxxxxx> wrote:
> > I need to create a QGraphics item with fixed size also when I scale the
> > scene with QGraphcsScene::scale().
>
Have a look at QGraphicsItem::ItemIgnoresTransformations ( using
QGraphicsItem::setFlags() ).
> Christopher
>
>
Hi Fabio & Cristopher
for me, QGraphicsItem::ItemIgnoresTransformations does not work: if
I put a QGraphicsItem on the scene it scales up and down when I scale
the view... maybe it works only when you have a QGraphicsItem inside
another QGraphicsItem... I don't know.
BTW, it seems there are some work in progress on this on qt4.4
Andy
--
[ signature omitted ]
Message 4 in thread
On Tue, 18 Mar 2008 12:42:19 +0100, "Andy Hirsh" <andhirsh@xxxxxxxxx> wrote:
> On Mon, 2008-03-17 at 21:05, Christopher Rasch-Olsen Raa wrote:
>
> On Mon, 17 Mar 2008 17:20:54 +0100, "fabiodago@xxxxxxxxx"
> <fabiodago@xxxxxxxxx> wrote:
>> > I need to create a QGraphics item with fixed size also when I scale
> the
>> > scene with QGraphcsScene::scale().
>>
> Have a look at QGraphicsItem::ItemIgnoresTransformations ( using
> QGraphicsItem::setFlags() ).
>> Christopher
>>
>>
> Hi Fabio & Cristopher
>
> for me, QGraphicsItem::ItemIgnoresTransformations does not work: if
> I put a QGraphicsItem on the scene it scales up and down when I scale
> the view... maybe it works only when you have a QGraphicsItem inside
> another QGraphicsItem... I don't know.
I've used QGraphicsItems right in QGraphicsScenes, not inside other QGI's. Works like a charm. :) Which version of QT are you using? What does you implementation look like?
> BTW, it seems there are some work in progress on this on qt4.4
>
> Andy
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 5 in thread
---------- Initial Header -----------
From : "Andy Hirsh" andhirsh@xxxxxxxxx
To : qt-interest@xxxxxxxxxxxxx
Cc :
Date : Tue, 18 Mar 2008 12:42:19 +0100
Subject : Re: QGraphicsItem with fixed size
> On Mon, 2008-03-17 at 21:05, Christopher Rasch-Olsen Raa wrote:
>
> On Mon, 17 Mar 2008 17:20:54 +0100, "fabiodago@xxxxxxxxx"
> <fabiodago@xxxxxxxxx> wrote:
> > > I need to create a QGraphics item with fixed size also when I scale the
> > > scene with QGraphcsScene::scale().
> >
> Have a look at QGraphicsItem::ItemIgnoresTransformations ( using
> QGraphicsItem::setFlags() ).
> > Christopher
> >
> >
> Hi Fabio & Cristopher
>
> for me, QGraphicsItem::ItemIgnoresTransformations does not work: if
> I put a QGraphicsItem on the scene it scales up and down when I scale
> the view... maybe it works only when you have a QGraphicsItem inside
> another QGraphicsItem... I don't know.
>
> BTW, it seems there are some work in progress on this on qt4.4
>
> Andy
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
I've tried QGraphicsItem::ItemIgnoresTransformations and it seems to work. But now there's another strange problem. When I right-click on an item with this flag set, sometimes is called the contextMenuEvent() method of another item instead of the one clicked. It's very strange: the items are also set to movable, but this property works correctly.
I'm using Qt 4.3.0. I'm going to upgrade to the last version and I hope that the problem is solved...
Regards.
Fabio.
--
[ signature omitted ]
Message 6 in thread
Hi,
On Tue, 18 Mar 2008 16:09:20 +0100, "fabiodago@xxxxxxxxx" <fabiodago@xxxxxxxxx> wrote:
> ---------- Initial Header -----------
>
> From : "Andy Hirsh" andhirsh@xxxxxxxxx
> To : qt-interest@xxxxxxxxxxxxx
> Cc :
> Date : Tue, 18 Mar 2008 12:42:19 +0100
> Subject : Re: QGraphicsItem with fixed size
>
>> On Mon, 2008-03-17 at 21:05, Christopher Rasch-Olsen Raa wrote:
>>
>> On Mon, 17 Mar 2008 17:20:54 +0100, "fabiodago@xxxxxxxxx"
>> <fabiodago@xxxxxxxxx> wrote:
>> > > I need to create a QGraphics item with fixed size also when I scale
> the
>> > > scene with QGraphcsScene::scale().
>> >
>> Have a look at QGraphicsItem::ItemIgnoresTransformations ( using
>> QGraphicsItem::setFlags() ).
>> > Christopher
>> >
>> >
>> Hi Fabio & Cristopher
>>
>> for me, QGraphicsItem::ItemIgnoresTransformations does not work: if
>> I put a QGraphicsItem on the scene it scales up and down when I scale
>> the view... maybe it works only when you have a QGraphicsItem inside
>> another QGraphicsItem... I don't know.
>>
>> BTW, it seems there are some work in progress on this on qt4.4
>>
>> Andy
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>
> I've tried QGraphicsItem::ItemIgnoresTransformations and it seems to work.
> But now there's another strange problem. When I right-click on an item with
> this flag set, sometimes is called the contextMenuEvent() method of another
> item instead of the one clicked. It's very strange: the items are also set
> to movable, but this property works correctly.
Sounds to me it's either caused by icorrect shape/boundingrect or some z-value. I advice you to investigate that a little further. Returning too large boundingrect's can sometimes provide some, uhm, interesting results. :)
> I'm using Qt 4.3.0. I'm going to upgrade to the last version and I hope
> that the problem is solved...
Could try, but I would guess the "error" is somewhere in your code. You could try posting a minimum compiling example here that we could have a look at.
> Regards.
>
> Fabio.
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 7 in thread
---------- Initial Header -----------
From : "Christopher Rasch-Olsen Raa" christopher@xxxxxxxxxxxxxxxx
To : qt-interest@xxxxxxxxxxxxx
Cc :
Date : Tue, 18 Mar 2008 23:49:28 +0000
Subject : Re: QGraphicsItem with fixed size
>
> Hi,
>
> On Tue, 18 Mar 2008 16:09:20 +0100, "fabiodago@xxxxxxxxx" <fabiodago@xxxxxxxxx> wrote:
> > ---------- Initial Header -----------
> >
> > From : "Andy Hirsh" andhirsh@xxxxxxxxx
> > To : qt-interest@xxxxxxxxxxxxx
> > Cc :
> > Date : Tue, 18 Mar 2008 12:42:19 +0100
> > Subject : Re: QGraphicsItem with fixed size
> >
> >> On Mon, 2008-03-17 at 21:05, Christopher Rasch-Olsen Raa wrote:
> >>
> >> On Mon, 17 Mar 2008 17:20:54 +0100, "fabiodago@xxxxxxxxx"
> >> <fabiodago@xxxxxxxxx> wrote:
> >> > > I need to create a QGraphics item with fixed size also when I scale
> > the
> >> > > scene with QGraphcsScene::scale().
> >> >
> >> Have a look at QGraphicsItem::ItemIgnoresTransformations ( using
> >> QGraphicsItem::setFlags() ).
> >> > Christopher
> >> >
> >> >
> >> Hi Fabio & Cristopher
> >>
> >> for me, QGraphicsItem::ItemIgnoresTransformations does not work: if
> >> I put a QGraphicsItem on the scene it scales up and down when I scale
> >> the view... maybe it works only when you have a QGraphicsItem inside
> >> another QGraphicsItem... I don't know.
> >>
> >> BTW, it seems there are some work in progress on this on qt4.4
> >>
> >> Andy
> >>
> >> --
> >> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> >> List archive and information: http://lists.trolltech.com/qt-interest/
> >>
> >>
> >
> > I've tried QGraphicsItem::ItemIgnoresTransformations and it seems to work.
> > But now there's another strange problem. When I right-click on an item with
> > this flag set, sometimes is called the contextMenuEvent() method of another
> > item instead of the one clicked. It's very strange: the items are also set
> > to movable, but this property works correctly.
>
> Sounds to me it's either caused by icorrect shape/boundingrect or some z-value. I advice you to investigate that a little further. Returning too large boundingrect's can sometimes provide some, uhm, interesting results. :)
>
> > I'm using Qt 4.3.0. I'm going to upgrade to the last version and I hope
> > that the problem is solved...
>
> Could try, but I would guess the "error" is somewhere in your code. You could try posting a minimum compiling example here that we could have a look at.
The bug was really in Qt. Upgrading to 4.3.4 the probem is solved. :-)
Thanks
Fabio.
>
> > Regards.
> >
> > Fabio.
> >
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> Christopher
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]