[Qt-interest] QGraphicsEffect drawing

Malyushytsky, Alex alex at wai.com
Tue Jul 19 02:40:24 CEST 2011


I think cash is function of QGraphicsView and depends on cacheMode ()
It might be that QGraphicsScene has to be changed to allow to access graphics effect set to item.

The only suggestions which comes to my mind now is to avoid to have to paint effect yourself.
This comes from the original goal - to skip some types when you call render()

Options:

a) Just remove items you do not want to be plotted from the scene before calling render, than add them back.
addItem() / removeItem();

Ugly, but should work.
You may disable update of the existing GraphicsView before doing this.

b) try to set QGraphicsItem::ItemHasNoContents flag to item before rendering.
I have not checked myself, but this suppose to prevent from QGraphicsItem::paint
to be called. Restore flags after rendering.

c) If above does not work, Subclass the items you need to be able to skip and custom flag which you will check in the paint to skip painting.


b) approach is preferable, c) is next in priority list, consider a) only if you really you don't want to override anything and b) did not work.

Alex


-----Original Message-----
From: Anton Chernov [mailto:mechernov at gmail.com]
Sent: Saturday, July 16, 2011 12:05 AM
To: Malyushytsky, Alex
Cc: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QGraphicsEffect drawing

class Q_GUI_EXPORT QGraphicsEffect : public QObject
{
    Q_OBJECT
    Q_FLAGS(ChangeFlags)
    Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY
enabledChanged)
public:
[...]
friend class QGraphicsItem;
friend class QGraphicsItemPrivate;
friend class QGraphicsScenePrivate;
friend class QWidget;
friend class QWidgetPrivate;
[...]
}

it seems that only QGraphicsScenePrivate has access to protected
effect members... if i reimplement ::render i still would need to
render the effects...

something is missing...

how does the actual source pixmap come to an effect? It seems that it
looks in the cache for a pixmap, but who and where renders this pixmap
to the cache?

2011/7/16 Malyushytsky, Alex <alex at wai.com>:
> How many subclasses of QGraphicsScene you have?
> Create a single subclass MyCraphicsScene which would implement flag and always derive from it instead of QGraphicsScene.
>
> Alex
>
> -----Original Message-----
> From: Anton Chernov [mailto:mechernov at gmail.com]
> Sent: Friday, July 15, 2011 1:26 PM
> To: Malyushytsky, Alex
> Cc: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QGraphicsEffect drawing
>
> I want avoid this because i every class i would have to have such a
> flag - that's miserable :) Bad c++ is miserable too, but takes less
> place in code :)
>
> 2011/7/15 Malyushytsky, Alex <alex at wai.com>:
>> QGraphicsEffect is base class for the for graphics effects.
>>
>> This probably means that when you set effect you do not create instance of QGraphicsEffect, but
>> QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, or QGraphicsOpacityEffect.
>>
>> So what you are trying to do below is illegal, cause none of the above classes are derived from
>> BadEffectAccessor.
>>
>> I can't give you direct answer on your question, but I don't think you need id.
>>
>> void QGraphicsScene::render calls
>>   virtual void drawItems(...) to draw items.
>>
>> All you need to make standard render work the way you want is override so it skips items you don't want to draw ( set flag before calling it for example ).
>>
>>
>> Regards,
>>  Alex
>>
>>
>> -----Original Message-----
>> From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Anton Chernov
>> Sent: Friday, July 15, 2011 12:47 AM
>> To: qt-interest at trolltech.com
>> Subject: [Qt-interest] QGraphicsEffect drawing
>>
>> Hi,
>>
>> I have a problem drawing QGraphicsEffects - a have a scene with lots
>> of items, but when rendering for print only particular items should be
>> drawn.
>> If i would call
>>
>> QGraphicsScene::render( ... )
>>
>> all will be drawn, so I use a custom renderer. Everything draws good
>> except the graphics effects - their
>>
>> draw( QPainter* painter )
>>
>> is protected.
>>
>> class BadEffectAccessor : public QGraphicsEffect
>> {
>>   public:
>>      void publicDraw( QPainter* painter ) { draw( painter ); }
>> };
>>
>> [...]
>> if( text->graphicsEffect() ) {
>>   BadEffectAccessor* accessor = static_cast< BadEffectAccessor* >(
>> text->graphicsEffect() );
>>   accessor->publicDraw( painter );
>> }
>> [...]
>>
>> Does not help, nothing is drawn! How do I draw the effects?
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>
>>
>


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”


More information about the Qt-interest-old mailing list