QGraphicsView MacOs retina [Qt5.5]



  • Hello everyone
    I have a problem with my application and retina screens.
    I can't render a pdf at 2x resolution.
    My class DOCView is a subclass of QGraphicsView

    DOCView::DOCView(QWidget *parent)
        : QGraphicsView(parent)
        , plugin(NULL)
        , scene(new QGraphicsScene(this))
        , currPageWebItm(NULL)
        , currPagePixItm(NULL)
        , pagePresMode(DOCPagePresentationMode::facing)
        , pageViewMode(DOCPageViewMode::fit_page)
        , backgroundColor()
        , actualZoom(1)
        , docStruct()
        , currentPage()
        , currentPagePair()
    {
        QList<int> c;
        c.append(229);
        c.append(229);
        c.append(229);
        backgroundColor = c;
        setScene(scene);
        // triyng to render a scene based on devicePixelRatio (doesn't work)
        scene->setSceneRect(0, 0, frameSize().width()*devicePixelRatio(), frameSize().height()*devicePixelRatio());
        QPixmap pixmap(frameSize().width(), frameSize().height());
        pixmap.fill(Qt::white);
        currPagePixItm = new QGraphicsPixmapItem(pixmap);
        currPagePixItm->setZValue(0);
        scene->addItem(currPagePixItm);
        show();
        setRenderHints(QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing);
    }
    

    And i have a method that select a "plugin" based type (the extension of the file)

    bool DOCView::selectPlugin(const QString& _path, const QString& _type)
    {
        deletePlugin();
        QString sfx = _type == "" ? QFileInfo(_path).suffix().toLower() : _type.toLower();
        if (sfx == "pdf")
            plugin = new PDFPlugin(this);
        else if (sfx == "swf")
            plugin = new SWFPlugin(this);
        else if (sfx == "jpg")
            plugin = new JPGPlugin(this);
        else if (sfx == "browser")
    	{
          plugin = new WEBPlugin(this);
        }
        else
            return false;
        return true;
    }
    

    and setPage Mehotd to display the selected page called by PDFPlugin

    void DOCView::setPage(QGraphicsWebView *_w)
    {
        if (currPageWebItm != NULL) scene->removeItem(currPageWebItm);
        currPageWebItm = _w;
        currPageWebItm->setZValue(0);
        currPageWebItm->setPos(QPoint(0,0));
        scene->addItem(currPageWebItm);
        scene->update();
        update();
    }
    

    So when i have a pdf file to render, i have an instance of PDFPlugin (we are using PDFTron framework https://www.pdftron.com/ )

    PDFPlugin code

    PDFPlugin::PDFPlugin(DOCView *_docView)
        : DOCPlugin(_docView)
        , pageViewMode(fit_page)
        , pageViewHint(DOCPageViewHint::none)
        , pdfDoc(NULL)
        , pdfView(new pdftron::PDF::PDFView())
        , pdfAbsolutePath("")
        , renderSem()
        , lastPage(1)
        , selecting(false)
        , selectedText("")
        , selX0(0.0)
        , selY0(0.0)
        , selection()
        , overlay_cnv()
        , overlay_pos()
        , overlay_flg()
        , overlay_pix()
    {
    
        pdfView->SetPagePresentationMode(pdftron::PDF::PDFView::e_facing);
        pdfView->SetPageViewMode(pdftron::PDF::PDFView::e_fit_page);
        pdfView->SetPageSpacing(0, 0, 0, 0);
        pdfView->SetPageBorderVisibility(false);
        pdfView->OnSize(docView->frameSize().width()*docView->devicePixelRatio(), docView->frameSize().height()*docView->devicePixelRatio());
        pdfView->SetAntiAliasing(true);
        pdfView->SetImageSmoothing(true);
        pdfView->SetRasterizerType(pdftron::PDF::PDFRasterizer::e_BuiltIn);
        pdfView->SetTextSelectionMode(pdftron::PDF::PDFView::e_structural);
    }
    

    I need an idea to solve this problem ...
    In the PdfTron documentation page don't talk about hdpi resolution and at the moment we can't migrate to Qt 5.6

    Thanks in advance
    GG


Log in to reply
 

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