PDA

View Full Version : Change Qt version and code stop working



rmagro
22nd September 2010, 16:57
Hi all,
I've just swiched from Qt 4.2.2 to Qt 4.4.3 anf the code I show below does not work anymore. It prints black lines .. any of you knows why it appens ??
Thank you in advance.
rmagro



QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);

QTableWidget *nuovaTableWidget = tableWidget;

QPrintDialog dlg(&printer, this);

if (dlg.exec() == QDialog::Accepted)
{
// calculate the total width/height table would need without scaling
const int rows = nuovaTableWidget->model()->rowCount();
const int cols = nuovaTableWidget->model()->columnCount();

double totalWidth = 0.0;

for (int c = 0; c < cols; ++c)
{
totalWidth += nuovaTableWidget->columnWidth(c);
}

double totalHeight = 0.0;

for (int r = 0; r < rows; ++r)
{
totalHeight += nuovaTableWidget->rowHeight(r);
}

double totalHeight1;
int numero_pagina = 1;

QPixmap pixmap(totalWidth, nuovaTableWidget->horizontalHeader()->height());
QPixmap pixmap1(totalWidth, totalHeight);

QPaintEvent event_1(QRect(0, 0, totalWidth, nuovaTableWidget->horizontalHeader()->height()));
QPaintEvent event_2(QRect(0, 0, totalWidth, totalHeight));

QPainter::setRedirected(nuovaTableWidget->horizontalHeader()->viewport(), &pixmap);
QApplication::sendEvent(nuovaTableWidget->horizontalHeader()->viewport(), &event_1);
QPainter::restoreRedirected(nuovaTableWidget->horizontalHeader()->viewport());

QPainter::setRedirected(nuovaTableWidget->viewport(), &pixmap1);
QApplication::sendEvent(nuovaTableWidget->viewport(), &event_2);
QPainter::restoreRedirected(nuovaTableWidget->viewport());

// print scaled pixmap
QPainter painter(&printer);

QDateTime dataDiOggi = QDateTime::currentDateTime();
QString dataDiOggiStringa = dataDiOggi.toString("dd.MM.yyyy hh:mm:ss");

painter.scale(4.5,4.5);
painter.drawPixmap(0, 100, totalWidth, nuovaTableWidget->horizontalHeader()->height(), pixmap);
painter.drawPixmap(0, 100+nuovaTableWidget->horizontalHeader()->height(), totalWidth, totalHeight, pixmap1);
}

rmagro
24th September 2010, 11:09
No one faced with this problem guys or any clue ?
Many thanks
rmagro

wysota
24th September 2010, 11:23
Usually when people come with problems like that at the end it occurs that in fact apart from changing Qt version they also changed (broke) their code or its environment (i.e. missing image plugins).

rmagro
24th September 2010, 17:54
It not absolutely my case. If I indeed switch back to Qt4.2.2 it start working again perfectly .. How come ??
Is there an alternative way (better way) to do the same ??
Thx
rmagro

tbscope
24th September 2010, 18:05
Please provide a minimal compiling example of your problem.

rmagro
28th September 2010, 18:35
Hi Guys,
at the following link you'll find a compiled example of my program:
www.businesskey.it/BIN.zip
To use it just run the parser.exe file, select the LicenzaDiKe.pdf.p7m file and wait a little bit till the table is shown.
Then click the "stampa" button to see how the funtion I posted print the line..
Many thanks for your suggestion and kind availability
rmagro

wysota
28th September 2010, 21:02
I think tbscope meant a minimal (i.e. 30 lines of code) and compilable (not "compiled") example.