Qt-interest Archive, September 2007
Direct render to a buffer
Message 1 in thread
I am using derived classes of QGraphicsItem to generate a
QGraphicsScene. I am doing this for an arbitrary number of windows
(hundreds). At present, I am rendering each QWidget in X11 and calling
QWidget::render() to render to an RGB Buffer, such as QPixmap or QImage.
Can I render directly to a QPixmap or QImage instead of the X11 screen?
Thanks,
Jonathan
--
[ signature omitted ]
Message 2 in thread
Jonathan Smith skrev:
> I am using derived classes of QGraphicsItem to generate a
> QGraphicsScene. I am doing this for an arbitrary number of windows
> (hundreds). At present, I am rendering each QWidget in X11 and
> calling QWidget::render() to render to an RGB Buffer, such as QPixmap
> or QImage.
>
> Can I render directly to a QPixmap or QImage instead of the X11 screen?
Sure, QImage is well suited for this.
Bo.
--
[ signature omitted ]
Message 3 in thread
How can I render a QWidget derived object directly to a QImage without
rendering it to the screen? To be more specific, I understand I can
manually call QWidget::render(...), but that requires the Widget to
exist as a Window that is visible. If the window is hidden, the image
doesn't come out. I would like the objects to exist completely within
QImage / QPixmap / etc., not the screen. Then, if I want to display it,
I have to render it in a window as an image.
Or, am I forced to do all effort within context of drawing directly to a
QImage?
Thank you,
Jonathan
Bo Thorsen wrote:
> Jonathan Smith skrev:
>> I am using derived classes of QGraphicsItem to generate a
>> QGraphicsScene. I am doing this for an arbitrary number of windows
>> (hundreds). At present, I am rendering each QWidget in X11 and
>> calling QWidget::render() to render to an RGB Buffer, such as QPixmap
>> or QImage.
>>
>> Can I render directly to a QPixmap or QImage instead of the X11 screen?
> Sure, QImage is well suited for this.
>
> Bo.
>
> --
> 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 4 in thread
Jonathan Smith skrev:
> How can I render a QWidget derived object directly to a QImage without
> rendering it to the screen? To be more specific, I understand I can
> manually call QWidget::render(...), but that requires the Widget to
> exist as a Window that is visible. If the window is hidden, the image
> doesn't come out. I would like the objects to exist completely within
> QImage / QPixmap / etc., not the screen. Then, if I want to display
> it, I have to render it in a window as an image.
>
> Or, am I forced to do all effort within context of drawing directly to
> a QImage?
Now I'm the one who answers without reading the question correctly.
Sorry about that.
No, there is no way you can render a widget anywhere but on the screen.
However, you can speed up this rendering by putting the image outside of
the visible area of the screens.
Bo.
> Thank you,
>
> Jonathan
>
> Bo Thorsen wrote:
>> Jonathan Smith skrev:
>>> I am using derived classes of QGraphicsItem to generate a
>>> QGraphicsScene. I am doing this for an arbitrary number of windows
>>> (hundreds). At present, I am rendering each QWidget in X11 and
>>> calling QWidget::render() to render to an RGB Buffer, such as
>>> QPixmap or QImage.
>>>
>>> Can I render directly to a QPixmap or QImage instead of the X11 screen?
>> Sure, QImage is well suited for this.
>>
>> Bo.
>>
>> --
>> 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/
>>
>>
>
> --
> 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
Hi Jonathan,
> How can I render a QWidget derived object directly to a QImage without
> rendering it to the screen? To be more specific, I understand I can
> manually call QWidget::render(...), but that requires the Widget to
> exist as a Window that is visible. If the window is hidden, the image
> doesn't come out. I would like the objects to exist completely within
> QImage / QPixmap / etc., not the screen. Then, if I want to display it,
> I have to render it in a window as an image.
>
> Or, am I forced to do all effort within context of drawing directly to a
> QImage?
You can perfectly render an invisible widget to any QPaintDevice. The
problem is that the widget isn't laid out correctly at the time you're
rendering. This is something we're looking into, but it's very tricky to
solve properly.
In the meantime you'd have to show and hide the widget or do similar
workarounds/hacks. You basically have to ensure that the widget is laid
out correctly at the time you're calling QWidget::render.
--
[ signature omitted ]
Message 6 in thread
Bjoern Erik Nilsen wrote:
> Hi Jonathan,
>
>> How can I render a QWidget derived object directly to a QImage without rendering it to the screen? To be more specific, I understand I can manually call
>> QWidget::render(...), but that requires the Widget to exist as a Window that is visible. If the window is hidden, the image doesn't come out. I would
>> like the objects to exist completely within QImage / QPixmap / etc., not the screen. Then, if I want to display it, I have to render it in a window as an
>> image.
>>
>> Or, am I forced to do all effort within context of drawing directly to a QImage?
>
> You can perfectly render an invisible widget to any QPaintDevice. The problem is that the widget isn't laid out correctly at the time you're rendering. This
> is something we're looking into, but it's very tricky to solve properly.
>
> In the meantime you'd have to show and hide the widget or do similar workarounds/hacks. You basically have to ensure that the widget is laid out correctly at
> the time you're calling QWidget::render.
>
The layout problem can be solved by forcibly calling the widget's layout manager's activate() function,
as in "layout()->activate()". This forces the layout manager to calculate the widget's layout, even if the widget
has never been shown before.
You can now call QWidget::render() and rest assured that the widget's internal layout is drawn properly into the image.
The same process applies for rendering parent widgets, which have sub-widgets, into an image.
We used this approach to solve a problem where changing the widget's layout (hiding a button) before the widget was
shown for the very first time caused the layout to break up if the button was shown again later.
- Antti Keskinen
--
[ signature omitted ]
Message 7 in thread
On fredag den 7. September 2007, Antti Keskinen wrote:
> Bjoern Erik Nilsen wrote:
> > Hi Jonathan,
> >
> >> How can I render a QWidget derived object directly to a QImage without
> >> rendering it to the screen? To be more specific, I understand I can
> >> manually call QWidget::render(...), but that requires the Widget to
> >> exist as a Window that is visible. If the window is hidden, the image
> >> doesn't come out. I would like the objects to exist completely within
> >> QImage / QPixmap / etc., not the screen. Then, if I want to display it,
> >> I have to render it in a window as an image.
> >>
> >> Or, am I forced to do all effort within context of drawing directly to a
> >> QImage?
> >
> > You can perfectly render an invisible widget to any QPaintDevice. The
> > problem is that the widget isn't laid out correctly at the time you're
> > rendering. This is something we're looking into, but it's very tricky to
> > solve properly.
> >
> > In the meantime you'd have to show and hide the widget or do similar
> > workarounds/hacks. You basically have to ensure that the widget is laid
> > out correctly at the time you're calling QWidget::render.
>
> The layout problem can be solved by forcibly calling the widget's layout
> manager's activate() function, as in "layout()->activate()". This forces
> the layout manager to calculate the widget's layout, even if the widget has
> never been shown before.
>
> You can now call QWidget::render() and rest assured that the widget's
> internal layout is drawn properly into the image. The same process applies
> for rendering parent widgets, which have sub-widgets, into an image.
>
> We used this approach to solve a problem where changing the widget's layout
> (hiding a button) before the widget was shown for the very first time
> caused the layout to break up if the button was shown again later.
Unfortunately I have seen several cases where layout()->activate() doesn't
work as it's supposed to.
So I guess the question is whether you feel lucky :-)
Bo.
--
[ signature omitted ]
Message 8 in thread
Antti Keskinen wrote:
> Bjoern Erik Nilsen wrote:
>> Hi Jonathan,
>>
>>> How can I render a QWidget derived object directly to a QImage without rendering it to the screen? To be more specific, I understand I can manually call
>>> QWidget::render(...), but that requires the Widget to exist as a Window that is visible. If the window is hidden, the image doesn't come out. I would
>>> like the objects to exist completely within QImage / QPixmap / etc., not the screen. Then, if I want to display it, I have to render it in a window as an
>>> image.
>>>
>>> Or, am I forced to do all effort within context of drawing directly to a QImage?
>> You can perfectly render an invisible widget to any QPaintDevice. The problem is that the widget isn't laid out correctly at the time you're rendering. This
>> is something we're looking into, but it's very tricky to solve properly.
>>
>> In the meantime you'd have to show and hide the widget or do similar workarounds/hacks. You basically have to ensure that the widget is laid out correctly at
>> the time you're calling QWidget::render.
>>
>
> The layout problem can be solved by forcibly calling the widget's layout manager's activate() function,
> as in "layout()->activate()". This forces the layout manager to calculate the widget's layout, even if the widget
> has never been shown before.
>
> You can now call QWidget::render() and rest assured that the widget's internal layout is drawn properly into the image.
> The same process applies for rendering parent widgets, which have sub-widgets, into an image.
>
> We used this approach to solve a problem where changing the widget's layout (hiding a button) before the widget was
> shown for the very first time caused the layout to break up if the button was shown again later.
This approach is not guaranteed to work as layout activation depends on
the widget's visibility, so when the widget is invisible you'd have to
do some magic.
The good news is that we'll make QWidget::render smart enough to do all
the magic itself. You simply don't have to worry about visibility or
layouts. Just call QWidget::render and it'll do what you want. This will
be done for Qt 4.4.
--
[ signature omitted ]
Message 9 in thread
On Wednesday 05 September 2007, Jonathan Smith wrote:
> I am using derived classes of QGraphicsItem to generate a
> QGraphicsScene. I am doing this for an arbitrary number of windows
> (hundreds). At present, I am rendering each QWidget in X11 and calling
> QWidget::render() to render to an RGB Buffer, such as QPixmap or QImage.
>
> Can I render directly to a QPixmap or QImage instead of the X11 screen?
>
> Thanks,
>
> Jonathan
>
> --
> 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/
Might
http://doc.trolltech.com/4.3/qgraphicsscene.html#render
help?
Flo
--
[ signature omitted ]