如何在QPainter :: translate中获得动态x和y坐标(qreal dx,qreal dy)

时间:2017-07-11 10:38:01

标签: qt sqlite

我想知道是否有人可以帮助我。我使用TablePrinter类在我的Qt项目中从Github https://github.com/T0ny0/Qt-Table-Printer找到它,从Sqlite数据库中打印出一些数据。我遇到的问题是我把两张桌子放在另一张桌子下面,我不知道如何或从哪里开始第二张桌子因为我不知道第一张桌子会有多少行。 我知道如果我增加' y' ' painter.translate(0,560);'它在两个表之间创造了一个差距,但我需要一个没有硬编码的动态方法,有人有任何建议吗? 非常感谢您的帮助。 这就是我尝试的方式;

QPrinter printer(QPrinter::HighResolution);
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
printer.setFullPage(false);
QPrintDialog dialog(&printer, this);
dialog.setWindowTitle(tr("Fire Muster Report"));

if (dialog.exec() == QDialog::Accepted)
    {
        QPainter painter;
        if(!painter.begin(&printer)) {
            qWarning() << "can't start printer";
            return;
        }

    TablePrinter tablePrinter(&painter, &printer);
    QVector<int> colStretch = QVector<int>() << 10 << 8 << 7 << 7;
    tablePrinter.setPen(QPen(QColor(0, 0, 0), 3, Qt::SolidLine)); // pen for borders
    tablePrinter.setHeaderColor(Qt::blue);
    tablePrinter.setContentColor(Qt::black);
    QFont font1; // font for headers
    font1.setBold(true);
    QFont font2; // font for content
    font2.setItalic(false);
    tablePrinter.setHeadersFont(font1);
    tablePrinter.setContentFont(font2);
    QVector<QString> headers = QVector<QString>() << "Name" << "Organisation" << "Contact No" << "Signed In";
    painter.setPen(QPen(Qt::blue));
    painter.drawText(painter.viewport().width()/3 - 40, 40, "Number of Visitors still signed in");
    painter.translate(0, 90); // start print point
    tablePrinter.setCellMargin(10, 7, 7, 7);
    tablePrinter.setPageMargin(100, 40, 40, 40);

    if(v != "0"){
        if(!tablePrinter.printTable(ui->tableView_visitRep->model(), colStretch, headers)) {
            qDebug() << tablePrinter.lastError();
        }
    }else{
        ui->label_visitCount->setText("No Visitors Signed In");
    }

    /***********************  Second Table  ************************/

    TablePrinter tablePrinter1(&painter, &printer);
    QVector<int> colStretch1 = QVector<int>() << 10 << 8 << 7 << 7;
    tablePrinter1.setPen(QPen(QColor(0, 0, 0), 3, Qt::SolidLine)); // pen for borders
    tablePrinter1.setHeaderColor(Qt::blue);
    tablePrinter1.setContentColor(Qt::black);
    QFont font11; // font for headers
    font11.setBold(true);
    QFont font21; // font for content
    font21.setItalic(false);
    tablePrinter1.setHeadersFont(font11);
    tablePrinter1.setContentFont(font21);
    QVector<QString> headers1 = QVector<QString>() << "Name" << "Department" << "Contact No" << "Signed In";
    painter.setPen(QPen(Qt::blue));
    painter.translate(0, 560); // start print point
    painter.drawText(painter.viewport().width()/3 - 0, 0, "Number of Employees still signed in");
    tablePrinter1.setCellMargin(10, 7, 7, 7);
    tablePrinter1.setPageMargin(100, 40, 40, 40);

    if(e != "0")
    {
        if(!tablePrinter1.printTable(ui->tableView_empRep->model(), colStretch1, headers1))
        {
            qDebug() << tablePrinter1.lastError();
        }
   }else{
        ui->label_empCount->setText("No Employee Signed In ");
   }
    painter.end();
}

1 个答案:

答案 0 :(得分:0)

我的猜测是使用int QSqlTableModel::rowCount(const QModelIndex &parent = QModelIndex()) const

  

返回给定父级下的行数。当父项有效时,表示rowCount返回父项的子项数。

在您的情况下ldapwhoami | sed -E 's/^dn:uid=([^,]*),ou=[^,]*,ou=([^,]*),.*ou=people,dc=42,dc=fr/uid=\1,ou=\2,ou=people,dc=42,dc=fr/g' SASL/GSSAPI authentication started SASL username: snegoesc@42.FR SASL SSF: 112 SASL data security layer installed. uid=snegoesc,ou=2017,ou=people,dc=42,dc=fr