QCustomPlot didnt show under Windows
-
I have wrote a code that show me a QCustomPlot on a QPrintPreviewDialog, but for some reason it dont work under Windows. With Linux i have a Page with the Plot, but under Windows the Page is empty. Anyone can help me?
void MainWindow::on_actionAnalysePrinting_triggered() { QPrinter printer; printer.setOrientation(QPrinter::Landscape); QPrintPreviewDialog preview(&printer, this); preview.setWindowFlags(Qt::Window); connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *))); preview.exec(); } void MainWindow::printPreview(QPrinter *printer) { ui->customPlotWidget->render(printer); }
-
Please. Nobody can help? Any ideas? If i want to draw something in printPreview the page is always blank.
-
Hi
did u install printer in windows?Else try CustomPlot forum. they might know if issues in windows.
-
no i have only a pdf printer installed. is it necessary? But i can print Text in another function with QPainter to the Device.
-
well a pdf printer should be just as good.
if you render some other widget, then it works? -
I tried to paint something else, but he dont paint anything on the page.
void MainWindow::printPreview(QPrinter *printer) { //ui->customPlotWidget->render(printer); QPainter painter(printer); painter.drawText(QPoint(50, 50), "12"); painter.end(); }
-
so its not related to customplot :)
Code seems fine at first sight. not sure why.
you dont need a
painter.begin(&printer); ?also is 50,50 inside the visible page?
maybe try
painter.drawText(QPoint(450, 450), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); -
@mrjj said:
painter.drawText(QPoint(450, 450), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
ok this works. so it could be the customplot widget. perhaps i need to ask in the customplot forum then. I tried now that
void MainWindow::printPreview(QPrinter *printer) { //ui->customPlotWidget->render(printer); QPainter painter; painter.begin(printer); ui->customPlotWidget->render(&painter); painter.end(); }
but this didnt work too.
-
@mrjj said:
painter.drawText(QPoint(450, 450), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
ok this works. so it could be the customplot widget. perhaps i need to ask in the customplot forum then. I tried now that
void MainWindow::printPreview(QPrinter *printer) { //ui->customPlotWidget->render(printer); QPainter painter; painter.begin(printer); ui->customPlotWidget->render(&painter); painter.end(); }
but this didnt work too.
@Fuel
Ok, so text was just outside:)
hi
maybe it just really, really small and outside area?
Normally u scale the widgets. as screen and printer have very different DPIQPainter painter; painter.begin(&printer); double xscale = printer.pageRect().width()/double(myWidget->width()); double yscale = printer.pageRect().height()/double(myWidget->height()); double 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); myWidget->render(&painter);
-
omg yes that works. but why i need to do that with windows? hmm dont really understand that.
-
omg yes that works. but why i need to do that with windows? hmm dont really understand that.
-
so different printer with different dpi would change the size? how can i prevent that? I always want the Fullsize on one page.
-
so different printer with different dpi would change the size? how can i prevent that? I always want the Fullsize on one page.
@Fuel
Yes, DPI means how many small dots/pixels pr inch.
A screen has may 72
and printer might have 1200
that is why we scale it.
So a widget that is 400 pixels will be extremely small on printer with high DPI.so you must always scale it.
If use use the sample code. it will always be same size. -
ok much thanks to you.
-
ok much thanks to you.