예제 #1
0
// Qt has qt_toX11Pixmap(), but that's sadly not public API. So the only
// option seems to be to create X11-based QPixmap using QPixmap::fromX11Pixmap()
// and draw the non-native pixmap to it.
// NOTE: The alpha-channel is not preserved if it exists, but for X pixmaps it generally should not be needed anyway.
QPixmap X11EmbedContainer::toX11Pixmap(const QPixmap& pix)
{
    if(pix.handle() != 0)   // X11 pixmap
        return pix;
    Pixmap xpix = XCreatePixmap(pix.x11Info().display(), RootWindow(pix.x11Info().display(), pix.x11Info().screen()),
                                pix.width(), pix.height(), QX11Info::appDepth());
    QPixmap wrk = QPixmap::fromX11Pixmap(xpix);
    QPainter paint(&wrk);
    paint.drawPixmap(0, 0, pix);
    paint.end();
    QPixmap ret = wrk.copy();
    wrk = QPixmap(); // reset, so that xpix can be freed (QPixmap does not own it)
    XFreePixmap(pix.x11Info().display(), xpix);
    return ret;
}
예제 #2
0
/*!
  \return A pixmap that can be used as backing store

  \param widget Widget, for which the backinstore is intended
  \param size Size of the pixmap
 */
QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
{
    QPixmap pm;

#define QWT_HIGH_DPI 1

#if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
    qreal pixelRatio = 1.0;

    if ( widget && widget->windowHandle() )
    {
        pixelRatio = widget->windowHandle()->devicePixelRatio();
    }
    else
    {
        if ( qApp )
            pixelRatio = qApp->devicePixelRatio();
    }

    pm = QPixmap( size * pixelRatio );
    pm.setDevicePixelRatio( pixelRatio );
#else
    Q_UNUSED( widget )
    pm = QPixmap( size );
#endif

#if 0
#ifdef Q_WS_X11
    if ( pm.x11Info().screen() != x11Info().screen() )
         pm.x11SetScreen( x11Info().screen() );
#endif
#endif

    return pm;
}