本文整理汇总了C++中QPixmap::setDevicePixelRatio方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::setDevicePixelRatio方法的具体用法?C++ QPixmap::setDevicePixelRatio怎么用?C++ QPixmap::setDevicePixelRatio使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::setDevicePixelRatio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setFile
void ImageView::setFile(const QString &fileName, const QByteArray &format)
{
if (format == QByteArrayLiteral("gif")) {
if (movie) {
movie->setFileName(fileName);
} else {
movie = new QMovie(fileName, format, this);
}
connect(movie, &QMovie::frameChanged, this, [this] {
const QPixmap ¤t_pixmap = movie->currentPixmap();
m_sourceSize = current_pixmap.size();
const QSize &dsize = qApp->desktop()->size();
qreal device_pixel_ratio = this->devicePixelRatioF();
QPixmap pixmap = current_pixmap.scaled(QSize(qMin((int)(dsize.width() * 0.7 * device_pixel_ratio), m_sourceSize.width()),
qMin((int)(dsize.height() * 0.8 * device_pixel_ratio), m_sourceSize.height())),
Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmap.setDevicePixelRatio(device_pixel_ratio);
setPixmap(pixmap);
});
movie->start();
return;
} else if (movie) {
movie->stop();
movie->deleteLater();
}
QImageReader reader(fileName, format);
m_sourceSize = reader.size();
const QSize &dsize = qApp->desktop()->size();
qreal device_pixel_ratio = this->devicePixelRatioF();
QPixmap pixmap = QPixmap::fromImageReader(&reader).scaled(QSize(qMin((int)(dsize.width() * 0.7 * device_pixel_ratio), m_sourceSize.width()),
qMin((int)(dsize.height() * 0.8 * device_pixel_ratio), m_sourceSize.height())),
Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmap.setDevicePixelRatio(device_pixel_ratio);
setPixmap(pixmap);
}
示例2: QUrl
DocsetMetadata::DocsetMetadata(const QJsonObject &jsonObject)
{
m_name = jsonObject[QStringLiteral("name")].toString();
m_title = jsonObject[QStringLiteral("title")].toString();
m_rawIcon = QByteArray::fromBase64(jsonObject[QStringLiteral("icon")].toString().toLocal8Bit());
m_icon.addPixmap(QPixmap::fromImage(QImage::fromData(m_rawIcon)));
m_rawIcon2x = QByteArray::fromBase64(jsonObject[QStringLiteral("icon2x")].toString()
.toLocal8Bit());
// TODO: Check on a high-resolution screen
if (qApp->devicePixelRatio() > 1.0) {
QPixmap pixmap = QPixmap::fromImage(QImage::fromData(m_rawIcon2x));
pixmap.setDevicePixelRatio(2.0);
m_icon.addPixmap(pixmap);
}
for (const QJsonValue &vv : jsonObject[QStringLiteral("aliases")].toArray())
m_aliases << vv.toString();
for (const QJsonValue &vv : jsonObject[QStringLiteral("versions")].toArray())
m_versions << vv.toString();
m_revision = jsonObject[QStringLiteral("revision")].toString();
m_feedUrl = QUrl(jsonObject[QStringLiteral("feed_url")].toString());
const QJsonArray urlArray = jsonObject[QStringLiteral("urls")].toArray();
for (const QJsonValue &url : urlArray)
m_urls.append(QUrl(url.toString()));
m_extra = jsonObject[QStringLiteral("extra")].toObject();
}
示例3: load
void Overview::load(const QImage& image, qreal pixelratio)
{
// Find minimum scale
m_min_scale_level = 9;
int side_max = std::max(image.width(), image.height()) * 0.9;
int side = 400;
if (side_max > side) {
for (int i = 9; i >= 0; --i) {
int side_test = std::floor(400.0 / ZoomSlider::scaleFactor(i));
if (side_test > side_max) {
break;
}
m_min_scale_level = i;
side = side_test;
}
} else {
side = side_max;
}
QPixmap pixmap = QPixmap::fromImage(image.scaled(side * pixelratio, side * pixelratio, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::AutoColor | Qt::AvoidDither);
pixmap.setDevicePixelRatio(pixelratio);
zoom(m_min_scale_level);
// Resize window
bool default_size = m_default;
QSize size = transform().mapRect(QRect(QPoint(0,0), pixmap.size() / pixelratio)).size();
setMinimumSize(size);
if (default_size) {
resize(minimumSize());
}
// Show overview
setPixmap(pixmap);
}
示例4: setMapForLocation
// Update the map for the given location.
void LocationDialog::setMapForLocation(const StelLocation& loc)
{
// Avoids useless processing
if (lastPlanet==loc.planetName)
return;
QPixmap pixmap;
// Try to set the proper planet map image
if (loc.planetName=="Earth")
{
// Special case for earth, we don't want to see the clouds
pixmap = QPixmap(":/graphicGui/world.png");
}
else
{
SolarSystem* ssm = GETSTELMODULE(SolarSystem);
PlanetP p = ssm->searchByEnglishName(loc.planetName);
if (p)
{
QString path = StelFileMgr::findFile("textures/"+p->getTextMapName());
if (path.isEmpty())
{
qWarning() << "ERROR - could not find planet map for " << loc.planetName;
return;
}
pixmap = QPixmap(path);
}
}
StelCore * core = StelApp::getInstance().getCore();
pixmap.setDevicePixelRatio(core->getCurrentStelProjectorParams().devicePixelsPerPixel);
ui->mapLabel->setPixmap(pixmap);
// For caching
lastPlanet = loc.planetName;
}
示例5: backingStore
/*!
\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;
}
示例6: cache
void Theme::cache(const QString& element, QPixmap& pixmap, const QRect& bounds, int angle) const
{
pixmap = QPixmap(bounds.size() * m_ratio);
pixmap.setDevicePixelRatio(m_ratio);
pixmap.fill(QColor(255, 255, 255, 0));
QPainter painter(&pixmap);
m_renderer->render(&painter, element, bounds);
// Handle rotated images
if (angle) {
Q_ASSERT(angle == 90 || angle == 180 || angle == 270);
painter.end();
pixmap = pixmap.transformed(QTransform().rotate(angle));
pixmap.setDevicePixelRatio(m_ratio);
}
}
示例7: QFrame
UpdateNotifier::UpdateNotifier(QWidget *parent)
: QFrame(parent),
m_icon(new QLabel),
m_title(new NormalLabel(tr("Updates"))),
m_content(new TipsLabel(tr("Updates detected, click to view"))),
m_closeButton(new DImageButton(this)),
m_settings(new QSettings("deepin", "dcc-update-notifier")),
m_updaterInter(new com::deepin::lastore::Updater("com.deepin.lastore",
"/com/deepin/lastore",
QDBusConnection::systemBus(), this))
{
setFixedHeight(80);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
m_content->setWordWrap(true);
m_content->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
const qreal ratio = devicePixelRatioF();
QIcon icon = QIcon::fromTheme("system-updated", QIcon::fromTheme("application-default-icon"));
m_icon->setFixedSize(48, 48);
QPixmap pixmap = icon.pixmap(m_icon->width() * ratio, m_icon->height() * ratio);
pixmap = pixmap.scaled(m_icon->width() * ratio, m_icon->height() * ratio,
Qt::KeepAspectRatioByExpanding,
Qt::SmoothTransformation);
pixmap.setDevicePixelRatio(ratio);
m_icon->setPixmap(pixmap);
m_closeButton->setFixedSize(14, 14);
m_closeButton->setObjectName("NotifyCloseButton");
m_closeButton->setVisible(false);
QVBoxLayout *contentLayout = new QVBoxLayout;
contentLayout->setSpacing(0);
contentLayout->setMargin(0);
contentLayout->addStretch();
contentLayout->addWidget(m_title);
contentLayout->addSpacing(4);
contentLayout->addWidget(m_content);
contentLayout->addStretch();
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setSpacing(10);
mainLayout->setContentsMargins(40, 0, 40, 0);
mainLayout->addWidget(m_icon);
mainLayout->addLayout(contentLayout);
setLayout(mainLayout);
m_updaterInter->setSync(false);
updatablePkgsChanged(m_updaterInter->updatablePackages());
connect(m_updaterInter, &com::deepin::lastore::Updater::UpdatablePackagesChanged,
this, &UpdateNotifier::updatablePkgsChanged);
connect(m_closeButton, &DImageButton::clicked, this, &UpdateNotifier::ignoreUpdates);
}
示例8: initializeWidget
void MorePage::initializeWidget()
{
//导航栏
QString strTitle = tr("更多...");
navigationBar = new NavigationBar(this);
navigationBar->setTitleText(strTitle);
QHBoxLayout* pHLTop = new QHBoxLayout();
pHLTop->addWidget(navigationBar);
pHLTop->setSpacing(0);
pHLTop->setMargin(0);
this->setTopbarLayout(pHLTop);
//个人信息
QLabel* themeWidget = new QLabel;
QPixmap pixmap = QPixmap(ImagePath::MOREPAGE_THEME);
pixmap.setDevicePixelRatio(2);
themeWidget->setAutoFillBackground(true);
themeWidget->setFixedHeight(this->screenHeight()*0.25);
themeWidget->setFixedWidth(this->screenWidth());
themeWidget->setPixmap(pixmap);
themeWidget->setScaledContents(true);
btnPersonalInfo = new QToolButton;
btnPersonalInfo->setFixedWidth(this->screenWidth());
btnPersonalInfo->setFixedHeight(this->screenHeight()*0.15);
btnPersonalInfo->setIconSize(QSize(btnPersonalInfo->height()*0.7, btnPersonalInfo->height()*0.7));
btnPersonalInfo->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btnPersonalInfo->setStyleSheet("font:16px; color:white;background-color:rgba(0,0,0,0)");
connect(btnPersonalInfo, SIGNAL(clicked()), SLOT(on_btnPersonal_clicked()));
QVBoxLayout* themeLayout = new QVBoxLayout;
themeLayout->addWidget(btnPersonalInfo);
themeLayout->setMargin(0);
themeWidget->setLayout(themeLayout);
//设置
btnSetting = new GroupButton;
btnSetting->setStyleSheet(SheetStyle::GROUPBUTTON_BOTTOMBORDER);
QPixmap settingPixmap(ImagePath::SETTING);
this->setGroupButton(btnSetting, settingPixmap, tr("设置"));
connect(btnSetting, SIGNAL(clicked()), SLOT(on_btnSetting_clicked()));
QVBoxLayout* vblTotalLayout = new QVBoxLayout;
vblTotalLayout->addWidget(themeWidget);
vblTotalLayout->addSpacing(this->screenHeight()*0.026);
vblTotalLayout->addWidget(btnSetting);
vblTotalLayout->setAlignment(Qt::AlignTop);
vblTotalLayout->setMargin(0);
vblTotalLayout->setSpacing(0);
this->setBodyPartLayout(vblTotalLayout);
//屏幕触摸滚动设置
this->setBodyScreenHeight(this->scrollAreaHasBottomBarHeight());
this->installScrollViewportArea();
this->loadLocalData(curAccountID);
}
示例9: updatePreview
void QuickBeamerDialog::updatePreview(const QString &theme)
{
QPixmap pixmap;
pixmap.load(":/images/beamer/"+theme+".png");
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
if (qApp->devicePixelRatio()>=2) pixmap.setDevicePixelRatio(qApp->devicePixelRatio());
#endif
labelImage->setPixmap(pixmap);
}
示例10: rasterToQPixmap
QPixmap rasterToQPixmap(const TRaster32P &ras, bool premultiplied,
bool setDevPixRatio) {
QPixmap pixmap = QPixmap::fromImage(rasterToQImage(ras, premultiplied));
if (setDevPixRatio) {
static int devPixRatio = QApplication::desktop()->devicePixelRatio();
pixmap.setDevicePixelRatio(devPixRatio);
}
return pixmap;
}
示例11: setDevicePixelRatio
//______________________________________________________________________________________
inline void setDevicePixelRatio( QPixmap& pixmap, qreal value )
{
#if QT_VERSION >= 0x050300
return pixmap.setDevicePixelRatio( value );
#else
Q_UNUSED( pixmap );
Q_UNUSED( value );
#endif
}
示例12: pixmap
/*!
\since 5.1
Returns a pixmap with the requested \a window \a size, \a mode, and \a
state, generating one if necessary.
The pixmap can be smaller than the requested size. If \a window is on
a high-dpi display the pixmap can be larger. In that case it will have
a devicePixelRatio larger than 1.
\sa actualSize(), paint()
*/
QPixmap QIcon::pixmap(QWindow *window, const QSize &size, Mode mode, State state) const
{
if (!d)
return QPixmap();
qreal devicePixelRatio = qt_effective_device_pixel_ratio(window);
// Handle the simple normal-dpi case:
if (!(devicePixelRatio > 1.0)) {
QPixmap pixmap = d->engine->pixmap(size, mode, state);
pixmap.setDevicePixelRatio(1.0);
return pixmap;
}
// Try get a pixmap that is big enough to be displayed at device pixel resolution.
QPixmap pixmap = d->engine->pixmap(size * devicePixelRatio, mode, state);
pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size()));
return pixmap;
}
示例13: renderSVG
QPixmap Utils::renderSVG(const QString &path, const QSize &size)
{
QImageReader reader;
QPixmap pixmap;
reader.setFileName(path);
if (reader.canRead()) {
const qreal ratio = qApp->devicePixelRatio();
reader.setScaledSize(size * ratio);
pixmap = QPixmap::fromImage(reader.read());
pixmap.setDevicePixelRatio(ratio);
} else {
pixmap.load(path);
}
return pixmap;
}
示例14: paintSelectedTabBackground
static void paintSelectedTabBackground(QPainter *painter, const QRect &spanRect)
{
const int verticalOverlap = 2; // Grows up and down for the overlaps
const int dpr = painter->device()->devicePixelRatio();
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(spanRect.width())
+ QLatin1Char('x') + QString::number(spanRect.height())
+ QLatin1Char('@') + QString::number(dpr);
QPixmap selection;
if (!QPixmapCache::find(cacheKey, &selection)) {
selection = QPixmap(QSize(spanRect.width(), spanRect.height() + 2 * verticalOverlap) * dpr);
selection.fill(Qt::transparent);
selection.setDevicePixelRatio(dpr);
QPainter p(&selection);
p.translate(QPoint(0, verticalOverlap));
const QRect rect(QPoint(), spanRect.size());
const QRectF borderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
//background
p.save();
QLinearGradient grad(rect.topLeft(), rect.topRight());
grad.setColorAt(0, QColor(255, 255, 255, 140));
grad.setColorAt(1, QColor(255, 255, 255, 210));
p.fillRect(rect, grad);
p.restore();
//shadows
p.setPen(QColor(0, 0, 0, 110));
p.drawLine(borderRect.topLeft() + QPointF(1, -1), borderRect.topRight() - QPointF(0, 1));
p.drawLine(borderRect.bottomLeft(), borderRect.bottomRight());
p.setPen(QColor(0, 0, 0, 40));
p.drawLine(borderRect.topLeft(), borderRect.bottomLeft());
//highlights
p.setPen(QColor(255, 255, 255, 50));
p.drawLine(borderRect.topLeft() + QPointF(0, -2), borderRect.topRight() - QPointF(0, 2));
p.drawLine(borderRect.bottomLeft() + QPointF(0, 1), borderRect.bottomRight() + QPointF(0, 1));
p.setPen(QColor(255, 255, 255, 40));
p.drawLine(borderRect.topLeft() + QPointF(0, 0), borderRect.topRight());
p.drawLine(borderRect.topRight() + QPointF(0, 1), borderRect.bottomRight() - QPointF(0, 1));
p.drawLine(borderRect.bottomLeft() + QPointF(0, -1), borderRect.bottomRight() - QPointF(0, 1));
QPixmapCache::insert(cacheKey, selection);
}
painter->drawPixmap(spanRect.topLeft() + QPoint(0, -verticalOverlap), selection);
}
示例15: fromSvgToPixmap
QPixmap* MainWindow::fromSvgToPixmap(const QSize &ImageSize, const QString &SvgFile)
{
const qreal PixelRatio = this->devicePixelRatio();
QSvgRenderer svgRenderer(SvgFile);
QPixmap *img = new QPixmap(ImageSize*PixelRatio);
QPainter Painter;
img->fill(Qt::transparent);
Painter.begin(img);
svgRenderer.render(&Painter);
Painter.end();
img->setDevicePixelRatio(PixelRatio);
return img;
}