Catch QFrame to QPixmap
-
Qt 5.6.1, Android.
I need catch content of QFrame to QPixmap. And then I will draw on this QPixmap by QPainter. I do this in class deriving from QFrame. Piece of code from paintEvent() of this class:QPixmap pm( size() ); m: pm.fill(Qt::black); // color noise appears without this render( &pm ); QPainter p(&pm); ....
Nothing. After render pm contains black field. Then I can draw on it, this works. The noise appearing in m: line tells me - render(&pm) does nothing. It does not change pm content. I tried use detailed call of render like this:
render( &pm, QPoint(0,0), QRegion(0,0,width(),height()) );
With this program fails.
What I am doing wrong? How can I catch content of QFrame to QPixmap? -
-
Hi
You assign painter to pixmap AFTER you grab.
Also where do you run this code ?
Should not be in constructor as it might not have right size.void ManualControlForm::screendump() { QPixmap pix; // might need to set size QPainter painter(&pix); painter.setRenderHint(QPainter::Antialiasing); frame->render(&painter); painter.end(); pix.save("/tmp/ramdisk/test2.png"); }
-
@mrjj
If render to QPainter then waterfall of messages(null):0 ((null)): QWidget::repaint: Recursive repaint detected
appears in app window and then app fails.
I run this code inside paintEvent() as I said before. Looks like render to QPainter calls paintEvent() - therefore recursion appears. But I need get content of frame inside paintEvent()... I have to think more...
-
@Gourmet
Well you are still not showing full code.
I done this many times and normally have zero issue with it.
(for screen shot features)
So you are clearly doing something odd, wrong or unexpected.
But you only said
"piece of code from paintEvent() of this class"
and show nothing more relevant information. -
Hi,
That's the main problem, you're asking the widget to paint itself when it's already painting itself, hence the error you get.
Do that somewhere else but not in the paintEvent of your QFrame.
-
Yes, gotcha... just made QPixmap pm class-wide field and removed pm = grab(QRect(QPoint(0,0),size())); to another method before update() - and all is working. To be on safe side just set pm = pm.scaled(size()); in init. Don't know is it necessary or not.
-
It's not since in the constructor the size of the widget is still unknown.