logo
down
shadow

Using QPainter with QPaintDevice multiple times


Using QPainter with QPaintDevice multiple times

By : gste
Date : November 22 2020, 03:03 PM
I wish this help you The warning tells you about creating multiple QPainters at one time. Since all paint events are processed in the main thread, they are processed consequently. As long as QPainter object is destroyed at the end of your event handler, the warning will not appear. Multiple consequent paintings on one device is fine.
However the architecture is questionable. For instance, if multiple widgets are painted this way, one of widgets will display old version of pixmap while second widget will display updated version. This inconsistency can be a problem. Putting any logic in paint event handlers is generaly pointless (and sometimes harmful). You should change pixmap when available data changes and just paint it in the paint event.
code :


Share : facebook icon twitter icon
What does QPainter::save () and QPainter::restore () do?

What does QPainter::save () and QPainter::restore () do?


By : crosire
Date : March 29 2020, 07:55 AM
will be helpful for those in need From the documentation:
Qt Cannot convert QPaintDevice to QImage

Qt Cannot convert QPaintDevice to QImage


By : DESHANA IT
Date : March 29 2020, 07:55 AM
this will help This sounds like silly, but I cannot take a screenshot of a QwebView. , Looks from the error that you need to pass image by pointer:
code :
painter.begin(&image);
Use one QPainter to paint multiple outputs at once: SVG and QImage

Use one QPainter to paint multiple outputs at once: SVG and QImage


By : user3328973
Date : March 29 2020, 07:55 AM
To fix the issue you can do I don't think you can get what you want out of the box. You could dig into the private implementation of the painter and come up with a way to do everything just once - generate each vector painter component and rasterize it to another paint device and move onto the next, but it will probably not be simple and hardly be worth it.
Just profile the two solutions you have so far and stick to the faster one, looks like the first one might be a tad more efficient.
How to print multiple qwidgets to a pdf in different pages using Qpainter?

How to print multiple qwidgets to a pdf in different pages using Qpainter?


By : Dinesh Singh
Date : March 29 2020, 07:55 AM
hope this fix your issue The problem is not that it does not print on the next page but the scale is not correct, you must reset all the transformations at the end of each iteration with resetTransform(). I prefer to save the widget in a QList .
code :
QList <QWidget *> widgets;
widgets.append({some widget});
[...]

QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("printer.pdf");

QPainter painter;

if (! painter.begin(&printer)) { // failed to open file
    qWarning("failed to open file, is it writable?");
}

for(auto widget: w){
    if(widget){
        if(widget->width() > 0 && widget->height() >0 ){

            qreal xscale = 0.9*printer.pageRect().width()/qreal(widget->width());
            qreal yscale = 0.9*printer.pageRect().height()/qreal(widget->height());

            qreal scale = qMin(xscale, yscale);

            painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
                              printer.paperRect().y() + printer.pageRect().height()/2);

            painter.scale(scale, scale);
            painter.translate(-width()/2, -height()/2);
            widget->render(&painter);
            painter.resetTransform();
            if(widget != widgets.last())
                printer.newPage();
        }
    }

}
painter.end();
QPainter::drawLine and QPainter::drawText with different color issue in Qt

QPainter::drawLine and QPainter::drawText with different color issue in Qt


By : samuel potato
Date : March 29 2020, 07:55 AM
like below fixes the issue This works for me with Qt 5.3; perhaps it was a bug in the version you were using?
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org