Printing QGraphicsScene with normalized coordinate system



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.