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. Qgraphicsview can't preview by QPrintPreviewDialog
Forum Updated to NodeBB v4.3 + New Features

Qgraphicsview can't preview by QPrintPreviewDialog

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.6k 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.
  • Q Offline
    Q Offline
    qylibohao
    wrote on last edited by
    #1

    @void MainWindow:: openPrintPreviewDialog()
    {
    QPrinter printer(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);

    QPainter painter(&printer);
    GetCurWindow()->getView()->render(&painter);
    QPrintPreviewDialog preview(&printer,this);
    connect(&preview, SIGNAL(paintRequested(QPrinter *)),this,SLOT(printPreView(QPrinter *)));
    preview.exec();
    }

    void MainWindow:: printPreView( QPrinter * printer)
    {
    ///view
    GraphicsView* currView = GetCurWindow()->getView();
    QPainter painter(printer);
    currView->render(&painter );
    }
    @
    why graphicsview can preview by qprintpreviewdialog ?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rokemoon
      wrote on last edited by
      #2

      Please use tag @ for code, just for better readability.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rokemoon
        wrote on last edited by
        #3

        Here the code that works for me:
        @

        void MainWindow::print()
        {
        QPrinter printer(QPrinter::HighResolution);
        printer.setPaperSize(QPrinter::A4);
        QPrintPreviewDialog preview(&printer, this);
        connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter*)));
        preview.exec();
        }

        void MainWindow::printPreview(QPrinter *printer)
        {
        QPainter painter(printer);
        m_graphicsView->render(&painter);
        }
        @

        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