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. QPdfView how to select text by mouse

QPdfView how to select text by mouse

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 65 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    songziming
    wrote last edited by
    #1

    I can load and render a PDF file using QPdfView:

    // inside MainWindow constructor
    QPdfView *pdf = new QPdfView();
    pdf->setPageMode(QPdfView::PageMode::MultiPage);
    pdf->setZoomMode(QPdfView::ZoomMode::FitToWidth);
    setCentralWidget(pdf);
    
    QPdfDocument *doc = new QPdfDocument(this);
    pdf->setDocument(doc);
    doc->load("C:\\path\\to\\sample.pdf");
    

    How to make text selectable using mouse?

    Do I need to convert mousePress/Move/Release position to pdf coordinate (and how)? And manually construct QPdfSelection object using start/end location?

    JonBJ 1 Reply Last reply
    0
    • S songziming

      I can load and render a PDF file using QPdfView:

      // inside MainWindow constructor
      QPdfView *pdf = new QPdfView();
      pdf->setPageMode(QPdfView::PageMode::MultiPage);
      pdf->setZoomMode(QPdfView::ZoomMode::FitToWidth);
      setCentralWidget(pdf);
      
      QPdfDocument *doc = new QPdfDocument(this);
      pdf->setDocument(doc);
      doc->load("C:\\path\\to\\sample.pdf");
      

      How to make text selectable using mouse?

      Do I need to convert mousePress/Move/Release position to pdf coordinate (and how)? And manually construct QPdfSelection object using start/end location?

      JonBJ Online
      JonBJ Online
      JonB
      wrote last edited by JonB
      #2

      @songziming
      Googling QPdfView select text gives e.g. https://askubuntu.com/questions/1071771/where-is-the-text-selection-tool-in-qpdfview. And see https://forum.qt.io/topic/115458/how-can-i-select-and-copy-text-from-a-qpdfview-widget.

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @songziming
        Googling QPdfView select text gives e.g. https://askubuntu.com/questions/1071771/where-is-the-text-selection-tool-in-qpdfview. And see https://forum.qt.io/topic/115458/how-can-i-select-and-copy-text-from-a-qpdfview-widget.

        S Offline
        S Offline
        songziming
        wrote last edited by
        #3

        @JonB I mean the class QPdfView in module QtPDF, not the standalone program qpdfviewer.

        The link you give is about the program.

        1 Reply Last reply
        0
        • KH-219DesignK Offline
          KH-219DesignK Offline
          KH-219Design
          wrote last edited by
          #4

          (disclaimer: I have not used either the standalone program nor the QPdfView class)

          Although @JonB appears to have provided links that refer to the standalone utility viewer, said viewer is open source and built using Qt. Therefore, (if no better option or no quicker tip appears in this forum), we can probably find clues about how to achieve text selection by looking at the code for the standalone utility and learning how it achieves this.

          Source code: https://git.launchpad.net/qpdfview

          (Learning from source code of qpdfview utility may or may not have been what @JonB had in mind, but either way the point stands. I do apologize if I am appearing to just "copy" or "regurgitate" JonB's answer as my own.)

          www.219design.com
          Software | Electrical | Mechanical | Product Design

          1 Reply Last reply
          2

          • Login

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