Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPrintPreviewDialog show Text from Database
Forum Updated to NodeBB v4.3 + New Features

QPrintPreviewDialog show Text from Database

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 837 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Im actually loading long Textblocks from a Database and want to show them in a QPrintPreviewDialog. But i dont find something how to append the textblocks to the page. How is it possible to append the textblocks from top to the bottom? everytime i need to set the QPainter Rect and the text overwrites in the first line. I didnt found anything in the Internet. there are only Examples how to show single lines, but not many textblocks. maybe i use QTextDocument too? Here is my actually code.

    void PrintDateRangeForm::on_pbAccept_clicked()
    {
        GDatabase db;
        QVector<QByteArray> cryptedEntrys;
        BigAES crypt;
        QDate from, to;
    
        from = QDate::fromString(ui->leFrom->text());
        to = QDate::fromString(ui->leTo->text());
    
        db.selectEntryBetween(&cryptedEntrys, &date, from, to);
    
        for (int i = 0; i < cryptedEntrys.count(); i++)
        {
            entrys.append(crypt.Decrypt(QByteArray::fromHex(cryptedEntrys[i]), aesKey));
        }
    
        QPrinter printer;
        printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
    
        QPrintPreviewDialog preview(&printer, this);
        preview.setWindowFlags ( Qt::Window );
        connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
        preview.exec();
    }
    
    void PrintDateRangeForm::printPreview(QPrinter *printer)
    {
        QPainter *painter = new QPainter(printer);
        int w = printer->pageRect().width();
        int h = printer->pageRect().height();
        QRect page( 0, 0, w, h );
        for (int i = 0; i < entrys.count(); i++)
        {
            painter->setFont(QFont("Tahoma",11));
            painter->drawText(page, Qt::AlignTop | Qt::AlignLeft, date[i].toString());
            //painter->setFont(QFont("Tahoma",9));
            //painter->drawText(10, 11, QString(entrys[i]));
        }
        painter->end();
    }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I have found a way to do that, but now i have another problem. From the Documentation i read that setPageSize() automatically sets page breaks for new pages, but that doesnt happen. someone have an idea?

      doc.setPageSize(QSizeF(printer->pageRect().size()));
      
      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        nobody has an idea how to make page breaks?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved