user3450805
user3450805

Reputation: 671

create widget preview in Qt

in Qt, is that possible to create temporary preview (a quick snapshot of GUI) of a widget just like the live taskbar preview in Windows7 (when we place our cursor on an item in the taskbar, a snapshot window shows on the top) ? any ideas

Upvotes: 3

Views: 520

Answers (2)

As evilruff has said, it's possible to render the widget into a paint device or a painter. You're paying the price for additional painting of the widget, of course.

Another option is to grab the composited widget's backing store directly as a QImage. In Qt 5 this works on all platforms with exception of widgets backed by an OpenGL context.

Upvotes: 0

evilruff
evilruff

Reputation: 4085

You can render a widget into an image using QWidget methods:

void    render(QPaintDevice * target, const QPoint & targetOffset = QPoint(), const QRegion & sourceRegion = QRegion(), RenderFlags renderFlags = RenderFlags( DrawWindowBackground | DrawChildren ))
void    render(QPainter * painter, const QPoint & targetOffset = QPoint(), const QRegion & sourceRegion = QRegion(), RenderFlags renderFlags = RenderFlags( DrawWindowBackground | DrawChildren ))

and use resulted QImage with desired size to show a preview to the user.

Upvotes: 2

Related Questions