QT GUI:QPrintDialog在调用时不会打开

时间:2016-02-18 17:54:14

标签: c++ qt

我遇到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();
    }
}

感谢您的帮助!!!

1 个答案:

答案 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();
    }
}