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. Couldn't print Arabic right
QtWS25 Last Chance

Couldn't print Arabic right

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 384 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.
  • D Offline
    D Offline
    deleted385
    wrote on last edited by deleted385
    #1

    Here's how it appears on UI and PDF:

    cap1.PNG

    looks ok on the UI BUT when I print it's terrible! Row Surah 1, Ayah 1 completely vanished in the PDF and those diacritical marks collude with previous/following rows. Here's the project in GitHub, I also have added the sample database, quran.db, for testing.

    JKSHJ 1 Reply Last reply
    0
    • D deleted385

      Here's how it appears on UI and PDF:

      cap1.PNG

      looks ok on the UI BUT when I print it's terrible! Row Surah 1, Ayah 1 completely vanished in the PDF and those diacritical marks collude with previous/following rows. Here's the project in GitHub, I also have added the sample database, quran.db, for testing.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Emon-Haque said in Couldn't print Arabic right:

      Here's the project in GitHub

      Please commit source code to GitHub as individual text files, not as a zipped file. That defeats the purpose of a version control system like Git.

      Anyway, please tell us how you tried to print as PDF.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      D 2 Replies Last reply
      1
      • JKSHJ JKSH

        @Emon-Haque said in Couldn't print Arabic right:

        Here's the project in GitHub

        Please commit source code to GitHub as individual text files, not as a zipped file. That defeats the purpose of a version control system like Git.

        Anyway, please tell us how you tried to print as PDF.

        D Offline
        D Offline
        deleted385
        wrote on last edited by deleted385
        #3

        @JKSH, here's my print function:

        void QueryResultView::printTable(){
            QPrinter printer;
            QPrintDialog dialog(&printer);
            if(dialog.exec() != QPrintDialog::Accepted) return;
            printer.setPageMargins(QMarginsF(72,72,72,72), QPageLayout::Point);
            printer.setResolution(fontMetrics().fontDpi());
            QTextDocument document;
            auto pageSize = printer.pageRect(QPrinter::DevicePixel).size();
            document.setPageSize(pageSize);
            QTextCursor cursor(&document);
            QTextTableFormat tableFormat;
            tableFormat.setBorder(0);
            tableFormat.setCellSpacing(0);
            tableFormat.setCellPadding(0);
            tableFormat.setHeaderRowCount(1);
            tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
            int row = resultModel->rowCount() + 1;
            int column = resultModel->columnCount();
            cursor.insertTable(row, column, tableFormat);
            addHeader(cursor);
            for (int r = 1; r < row; r++) {
                for (int c = 0; c < column; c++) {
                    auto index = table->model()->index(r, c);
                    cursor.insertText( table->model()->data(index).toString() );
                    cursor.movePosition(QTextCursor::NextCell);
                }
            }
            auto date = QDateTime::currentDateTime().toString("dd MMMM, yyyy");
            auto time = QDateTime::currentDateTime().toString("hh:mm:ss AP");
            int pageCount = document.pageCount();
            QPainter painter(&printer);
            for (int pageNo = 0; pageNo < pageCount; pageNo++) {
                if (pageNo > 0) printer.newPage();
                const QRectF currentPage(0, pageNo * pageSize.height(), pageSize.width(), pageSize.height());
                painter.save();
                painter.translate(0, -currentPage.top());
                document.drawContents(&painter, QRectF(0, currentPage.top(), pageSize.width(), pageSize.height()));
                painter.restore();
                QRectF footerRect(0, pageSize.height(), pageSize.width(), fontMetrics().height());
                painter.drawLine(footerRect.left(), footerRect.top(), footerRect.right(), footerRect.top());
                painter.drawText(footerRect, Qt::AlignVCenter | Qt::AlignLeft, "Generated on " + date + " | " + time);
                painter.drawText(footerRect, Qt::AlignVCenter | Qt::AlignRight, QString("Page: %1/%2").arg(pageNo + 1).arg(pageCount));
            }
        }
        

        When I upload a folder in github, it doesn't work!

        EDIT
        When the print dialog appeared, I selected Microsoft Print to PDF and clicked Print after selecting file location and providing file name.

        1 Reply Last reply
        0
        • JKSHJ JKSH

          @Emon-Haque said in Couldn't print Arabic right:

          Here's the project in GitHub

          Please commit source code to GitHub as individual text files, not as a zipped file. That defeats the purpose of a version control system like Git.

          Anyway, please tell us how you tried to print as PDF.

          D Offline
          D Offline
          deleted385
          wrote on last edited by deleted385
          #4

          @JKSH, to bring in the first row, I should've had r - 1 in for:

          for (int r = 1; r < row; r++) {
              for (int c = 0; c < column; c++) {
                  auto index = table->model()->index(r - 1, c);
                  cursor.insertText( table->model()->data(index).toString() );
                  cursor.movePosition(QTextCursor::NextCell);
              }
          }
          

          copy/paste error! BUT those diacritical marks still overlaps with previous/following rows and becomes unreadable.

          JKSHJ 1 Reply Last reply
          0
          • D deleted385

            @JKSH, to bring in the first row, I should've had r - 1 in for:

            for (int r = 1; r < row; r++) {
                for (int c = 0; c < column; c++) {
                    auto index = table->model()->index(r - 1, c);
                    cursor.insertText( table->model()->data(index).toString() );
                    cursor.movePosition(QTextCursor::NextCell);
                }
            }
            

            copy/paste error! BUT those diacritical marks still overlaps with previous/following rows and becomes unreadable.

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @deleted385 said in Couldn't print Arabic right:

            those diacritical marks still overlaps with previous/following rows and becomes unreadable.

            I'm not familiar with the QTextCursor API, so I'll let someone else comment on your code.

            For now, I recommend you just try to print a simple PDF with 2 lines. Keep modifying the code until you get 2 lines that don't overlap.

            When I upload a folder in github, it doesn't work!

            GitHub is not for uploading files. You should commit your code on your PC and then push it to GitHub: https://docs.github.com/en/get-started/quickstart/hello-world

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            1

            • Login

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