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. Printing QGraphicsScene with normalized coordinate system
Forum Updated to NodeBB v4.3 + New Features

Printing QGraphicsScene with normalized coordinate system

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 802 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.
  • I Offline
    I Offline
    IvanM1976
    wrote on last edited by
    #1

    Hello,

    I'm trying to using QGraphicsView/QGraphicsScene to render 2D objects using a normalized (right hand) coordinate system and a specific logical unit 1px=0.01 mm.
    This is the same resolution you get setting MM_HIMETRIC with MFC.

    For the screen I resolved this way:

    QGraphicsView* pView = new QGraphicsView();
    QGraphicsScene* pScene = new QGraphicsScene(pView);
    pScene->setSceneRect(0,0,21000,-29700);
    pView->setScene(pScene);
    double scaleX = ((double)pView->physicalDpiX())/2540.0;
    double scaleY = ((double)pView->physicalDpiY())/2540.0;
    pView->scale(scaleX,scaleY);
    QTransform tr;
    tr = tr.scale(1.0,-1.0);
    pView->setTransform(tr,true);
    pScene->addLine(100,-1000,1100,-1000,QPen(Qt::black,10));

    with the code above, the line will be long 1cm.

    Now I find some problems in printing with this coordinate system.

    QPrinter printer(QPrinter::HighResolution);

    printer.setPageSize(QPrinter::A4);

    if (QPrintDialog(&printer).exec() == QDialog::Accepted) {
    QPainter painter(&printer);
    //......initialization of viewport/ window here?????
    painter.setRenderHint(QPainter::Antialiasing);
    pScene->render(&painter);
    }

    How should I set viewport/Window of painter in order to get the same results of the screen rendering?

    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