我遇到QPrintDialog问题。当我调用函数.exec();
时,它不会打开以下是代码:
void MainWindow::on_action_Print_triggered(int b,const QString &arg1 )
{
QString textFromField = ui->textEdit->toPlainText();
QPrinter printer;
QPrintDialog *printDialog = new QPrintDialog(&printer, this);
printDialog->setWindowTitle("Print");
printDialog->exec();
if(printDialog->exec()==QDialog::Accepted)
{
QPainter painter;
painter.begin(&printer);
painter.setFont(QFont(arg1,b));
painter.drawText(100, 100, 500, 500, Qt::AlignLeft | Qt::AlignTop, textFromField);
painter.end();
}
}
感谢您的帮助!!!
答案 0 :(得分:0)
该函数不能包含参数。纠正的功能:
void MainWindow::on_actionPrint_triggered()
{
QString FONTH, a;
int SIZEOFFONTH;
a=ui->comboBox->currentText();
SIZEOFFONTH=a.split(" ")[0].toInt();
FONTH=ui->fontComboBox->currentText();
ui->label->setText("Printing");
QString textFromField = ui->textEdit->toPlainText();
QPrinter printer;
QPrintDialog *printDialog = new QPrintDialog(&printer, this);
printDialog->setWindowTitle("Print");
if(printDialog->exec()==QDialog::Accepted)
{
QPainter painter;
painter.begin(&printer);
painter.setFont(QFont(FONTH,SIZEOFFONTH));
painter.drawText(100, 100, 500, 500, Qt::AlignLeft | Qt::AlignTop, textFromField);
painter.end();
}
}