how to set QGraphicstextitem's height in mm?
-
code to add QGraphicstextitem QFont font; font.setFamily(defaultFamily); font.setPointSizeF(defaultTxtsize* mmtopt); QGraphicstextItem* textitem = new QGraphicstextItem(); textitem->pointSize = defaultTxtsize; textitem->setPlainText(textEdit->text()); textitem->setFont(font); textitem->setDefaultTextColor(defaultColor); textitem->setPos(gridPosition.x()-5,gridPosition.y()-7); textitem->setTextInteractionFlags(Qt::TextEditable); addItem(textitem); code to export to pdf: printer = new QPrinter(QPrinter::HighResolution); printer->setOutputFormat(QPrinter::PdfFormat); printer->setOutputFileName(pdfFile);//pdfFile contains the name of the pdf which we have to print printer->setPageSize(QPrinter::A3); printer->setOrientation(QPrinter::Landscape); printer->setPdfVersion(QPagedPaintDevice::PdfVersion_1_6); QPainter painter(printer); painter.setRenderHint(QPainter::Antialiasing); scene->setBackgroundBrush(QBrush(Qt::white)); scene->render(&painter); //defaultTxtsize = input given by the user in mm mmtopt = 2.83465(factor to convert mm to points)I want to add QGraphicsTextitem with its height measured in millimeter, export it to pdf and print it. After printing I checked using ruler manually and there is difference in text height(user input is 2 mm and in paper it shows 1mm). can anyone help me to find out the mistake.
-
code to add QGraphicstextitem QFont font; font.setFamily(defaultFamily); font.setPointSizeF(defaultTxtsize* mmtopt); QGraphicstextItem* textitem = new QGraphicstextItem(); textitem->pointSize = defaultTxtsize; textitem->setPlainText(textEdit->text()); textitem->setFont(font); textitem->setDefaultTextColor(defaultColor); textitem->setPos(gridPosition.x()-5,gridPosition.y()-7); textitem->setTextInteractionFlags(Qt::TextEditable); addItem(textitem); code to export to pdf: printer = new QPrinter(QPrinter::HighResolution); printer->setOutputFormat(QPrinter::PdfFormat); printer->setOutputFileName(pdfFile);//pdfFile contains the name of the pdf which we have to print printer->setPageSize(QPrinter::A3); printer->setOrientation(QPrinter::Landscape); printer->setPdfVersion(QPagedPaintDevice::PdfVersion_1_6); QPainter painter(printer); painter.setRenderHint(QPainter::Antialiasing); scene->setBackgroundBrush(QBrush(Qt::white)); scene->render(&painter); //defaultTxtsize = input given by the user in mm mmtopt = 2.83465(factor to convert mm to points)I want to add QGraphicsTextitem with its height measured in millimeter, export it to pdf and print it. After printing I checked using ruler manually and there is difference in text height(user input is 2 mm and in paper it shows 1mm). can anyone help me to find out the mistake.
@Selvajothi said in how to set QGraphicstextitem's height in mm?:
font.setPointSizeF(defaultTxtsize* mmtopt);
You got your units mixed up. Point size is given in 1/72 inch. So if you want your text to be 2 mm high, you just need to convert 2 mm to inch and multiply by 72
-
I have changed as u mentioned and printed it in paper. Still it is not giving the correct height when measured using ruler.font.setPointSizeF(defaultTxtSize0.039370172)
Here defaultRxtSize is 10mm for the attached image.