Rendering QWidget with children overriding paintEvent
-
Hello,
I want to render a widget to save it in clipboard.
Widget has children and one of them override paintEvent, setting transformations on a custom QPainter.void ImagesUtils::enregisterDansClipboard(QWidget* parent, QWidget* widgetACapturer) { QPixmap pixmap(widgetACapturer->size()); widgetACapturer->render(&pixmap, QPoint(), QRegion(0, 0, widgetACapturer->size().width(), widgetACapturer->size().height())); QApplication::clipboard()->setImage(pixmap.toImage()); }
void WidgetAxe::paintEvent(QPaintEvent *event) { QPainter* painter = new QPainter(this); painter->translate(rect().topRight()); painter->rotate(-90); painter->scale(-1.0, 1.0); ... }
This widget is drawn (and other children too), but the transformations are ignored. I guess it's is due to the fact that i use a custom QPainter, but I don't know how to resolve it.
Thanks for your help.
-
Hi and welcome to devnet,
Can you provide a minimal compilable example that shows that issue ?
-
@Josselin said in Rendering QWidget with children overriding paintEvent:
QPainter* painter = new QPainter(this);
Do you also delete this painter again? Why do you create it on the heap at all?
And when you don't delete it you likely forgot to call QPainter:end() -
@Christian-Ehrlicher said in Rendering QWidget with children overriding paintEvent:
@Josselin said in Rendering QWidget with children overriding paintEvent:
QPainter* painter = new QPainter(this);
Do you also delete this painter again? Why do you create it on the heap at all?
And when you don't delete it you likely forgot to call QPainter:end()Exactly. I forgot to delete my painter. Thanks for your reply, it works perfectly.
The use of pointer is probably a bad habit (I'm a java developer, and i'm converting python code ), when I have to pass my object to a methodThanks for your help.
-
@Josselin said in Rendering QWidget with children overriding paintEvent:
when I have to pass my object to a method
You can pass a pointer to a stack allocated object