Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved QPrintPreviewDialog show Text from Database

    General and Desktop
    1
    3
    601
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by

      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 Reply Quote 0
      • ?
        A Former User last edited by

        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 Reply Quote 0
        • ?
          A Former User last edited by

          nobody has an idea how to make page breaks?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post