本文整理汇总了C++中QPixmap::devicePixelRatio方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::devicePixelRatio方法的具体用法?C++ QPixmap::devicePixelRatio怎么用?C++ QPixmap::devicePixelRatio使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::devicePixelRatio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void SearchButton::paintEvent(QPaintEvent *e) {
Q_UNUSED(e);
QPainter painter(this);
const int h = height();
int iconSize = 16;
if (h > 32) iconSize = 22;
QPixmap p = IconUtils::icon("edit-find").pixmap(iconSize, iconSize);
int x = (width() - p.width() / p.devicePixelRatio()) / 2;
int y = (h - p.height() / p.devicePixelRatio()) / 2;
painter.drawPixmap(x, y, p);
}
示例2: sizeHint
QSize DConfigDlgListViewDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (!index.isValid())
{
return QSize(0, 0);
}
QStyleOptionViewItemV4 opt(option);
opt.showDecorationSelected = true;
QStyle* const style = opt.widget ? opt.widget->style() : QApplication::style();
int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize);
const QString text = index.model()->data(index, Qt::DisplayRole).toString();
const QIcon icon = index.model()->data(index, Qt::DecorationRole).value<QIcon>();
const QPixmap pixmap = icon.pixmap(iconSize, iconSize);
QFontMetrics fm = option.fontMetrics;
int gap = fm.height();
int wp = pixmap.width() / pixmap.devicePixelRatio();
int hp = pixmap.height() / pixmap.devicePixelRatio();
if (hp == 0)
{
/**
* No pixmap loaded yet, we'll use the default icon size in this case.
*/
hp = iconSize;
wp = iconSize;
}
QTextLayout iconTextLayout(text, option.font);
int wt = layoutText(&iconTextLayout, qMax(3 * wp, 8 * fm.height()));
int ht = iconTextLayout.boundingRect().height();
int width, height;
if (text.isEmpty())
{
height = hp;
}
else
{
height = hp + ht + 10;
}
width = qMax(wt, wp) + gap;
return QSize(width, height);
}
示例3: paintEvent
void RefineSearchButton::paintEvent(QPaintEvent *) {
QColor backgroundColor = palette().windowText().color();
backgroundColor.setAlpha(hovered ? 192 : 170);
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(backgroundColor);
painter.drawEllipse(QPoint(width(), height()), width() - 2, height() - 2);
QPixmap pixmap =
IconUtils::iconPixmap("refine-search", 24, backgroundColor, devicePixelRatioF());
int pw = pixmap.width() / pixmap.devicePixelRatio();
int ph = pixmap.height() / pixmap.devicePixelRatio();
painter.drawPixmap(width() - pw - 6, height() - ph - 6, pw, ph, pixmap);
}
示例4: Copy
void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource)
{
Q_ASSERT(painter);
SurfaceImpl &si = static_cast<SurfaceImpl &>(surfaceSource);
if (si.pd)
{
QPixmap *pm = static_cast<QPixmap *>(si.pd);
qreal x = from.x;
qreal y = from.y;
qreal width = rc.right - rc.left;
qreal height = rc.bottom - rc.top;
#if QT_VERSION >= 0x050000
qreal dpr = pm->devicePixelRatio();
x *= dpr;
y *= dpr;
width *= dpr;
height *= dpr;
#endif
painter->drawPixmap(QPointF(rc.left, rc.top), *pm,
QRectF(x, y, width, height));
}
}
示例5: setPixmap
void MainWindow::setPixmap(const QPixmap &pixmap)
{
pixmapLabel->setPixmap(pixmap);
QSize size = pixmap.size() / pixmap.devicePixelRatio();
if (size - QSize(1, 0) == pixmapLabelArea->maximumViewportSize())
size -= QSize(1, 0);
pixmapLabel->resize(size);
}
示例6: scalePixmapKeepingAspectRatio
QPixmap scalePixmapKeepingAspectRatio(QPixmap pixmap, QSize size,
QColor color) {
if (pixmap.isNull()) return pixmap;
if (pixmap.devicePixelRatio() > 1.0) size *= pixmap.devicePixelRatio();
if (pixmap.size() == size) return pixmap;
QPixmap scaledPixmap =
pixmap.scaled(size.width(), size.height(), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
QPixmap newPixmap(size);
newPixmap.fill(color);
QPainter painter(&newPixmap);
painter.drawPixmap(double(size.width() - scaledPixmap.width()) * 0.5,
double(size.height() - scaledPixmap.height()) * 0.5,
scaledPixmap);
newPixmap.setDevicePixelRatio(pixmap.devicePixelRatio());
return newPixmap;
}
示例7: pixmapDevicePixelRatio
static qreal pixmapDevicePixelRatio(const QPixmap &pixmap)
{
#if QT_VERSION > 0x050000
return pixmap.devicePixelRatio();
#else
Q_UNUSED(pixmap);
return 1.0;
#endif
}
示例8: paint
void DConfigDlgListViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (!index.isValid())
{
return;
}
QStyleOptionViewItemV4 opt(option);
opt.showDecorationSelected = true;
QStyle* const style = opt.widget ? opt.widget->style() : QApplication::style();
int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize);
const QString text = index.model()->data(index, Qt::DisplayRole).toString();
const QIcon icon = index.model()->data(index, Qt::DecorationRole).value<QIcon>();
const QPixmap pixmap = icon.pixmap(iconSize, iconSize);
QFontMetrics fm = painter->fontMetrics();
int wp = pixmap.width() / pixmap.devicePixelRatio();
int hp = pixmap.height() / pixmap.devicePixelRatio();
QTextLayout iconTextLayout(text, option.font);
QTextOption textOption(Qt::AlignHCenter);
iconTextLayout.setTextOption(textOption);
int maxWidth = qMax(3 * wp, 8 * fm.height());
layoutText(&iconTextLayout, maxWidth);
QPen pen = painter->pen();
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? QPalette::Normal
: QPalette::Disabled;
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
{
cg = QPalette::Inactive;
}
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
if (option.state & QStyle::State_Selected)
{
painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
}
else
{
painter->setPen(option.palette.color(cg, QPalette::Text));
}
painter->drawPixmap(option.rect.x() + (option.rect.width() / 2) - (wp / 2), option.rect.y() + 5, pixmap);
if (!text.isEmpty())
{
iconTextLayout.draw(painter, QPoint(option.rect.x() + (option.rect.width() / 2) - (maxWidth / 2), option.rect.y() + hp + 7));
}
painter->setPen(pen);
drawFocus(painter, option, option.rect);
}
示例9: devicePixelRatio
//______________________________________________________________________________________
inline qreal devicePixelRatio( const QPixmap& pixmap )
{
#if QT_VERSION >= 0x050300
return pixmap.devicePixelRatio();
#else
Q_UNUSED( pixmap );
return 1;
#endif
}
示例10: cIntRetinaFactor
RippleAnimation::Ripple::Ripple(const style::RippleAnimation &st, const QPixmap &mask, Fn<void()> update)
: _st(st)
, _update(update)
, _origin(mask.width() / (2 * cIntRetinaFactor()), mask.height() / (2 * cIntRetinaFactor()))
, _radiusFrom(mask.width() + mask.height())
, _frame(mask.size(), QImage::Format_ARGB32_Premultiplied) {
_frame.setDevicePixelRatio(mask.devicePixelRatio());
_radiusTo = _radiusFrom;
_hide.start(_update, 0., 1., _st.hideDuration);
}
示例11: drawIcon
static void drawIcon(const QIcon &icon, const QRect &r, QPainter *p, const QSize &iconSize, bool selected)
{
QPixmap px = icon.pixmap(iconSize, selected ? QIcon::Selected : QIcon::Normal);
#if QT_VERSION >= 0x050100
QSize layoutSize = px.size() / px.devicePixelRatio();
#else
QSize layoutSize = px.size();
#endif
p->drawPixmap(r.x()+(r.width()-layoutSize.width())/2.0, r.y()+(r.height()-layoutSize.height())/2.0, layoutSize.width(), layoutSize.height(), px);
}
示例12: getPixmapSize
static QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format)
{
QPixmap pm;
const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth);
const int width = qRound(format.width());
const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight);
const int height = qRound(format.height());
QSize size(width, height);
if (!hasWidth || !hasHeight) {
pm = getPixmap(doc, format);
const int pmWidth = pm.width() / pm.devicePixelRatio();
const int pmHeight = pm.height() / pm.devicePixelRatio();
if (!hasWidth) {
if (!hasHeight)
size.setWidth(pmWidth);
else
size.setWidth(qRound(height * (pmWidth / (qreal) pmHeight)));
}
if (!hasHeight) {
if (!hasWidth)
size.setHeight(pmHeight);
else
size.setHeight(qRound(width * (pmHeight / (qreal) pmWidth)));
}
}
qreal scale = 1.0;
QPaintDevice *pdev = doc->documentLayout()->paintDevice();
if (pdev) {
if (pm.isNull())
pm = getPixmap(doc, format);
if (!pm.isNull())
scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
}
size *= scale;
return size;
}
示例13: setPixmap
void QWindowsDragCursorWindow::setPixmap(const QPixmap &p)
{
if (p.cacheKey() == m_pixmap.cacheKey())
return;
const QSize oldSize = m_pixmap.size();
QSize newSize = p.size();
qCDebug(lcQpaMime) << __FUNCTION__ << p.cacheKey() << newSize;
m_pixmap = p;
if (oldSize != newSize) {
const qreal pixDevicePixelRatio = p.devicePixelRatio();
if (pixDevicePixelRatio > 1.0 && qFuzzyCompare(pixDevicePixelRatio, devicePixelRatio()))
newSize /= qRound(pixDevicePixelRatio);
resize(newSize);
}
if (isVisible())
update();
}
示例14: sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (standard) {
return QStyledItemDelegate::sizeHint(option, index);
}
if (!index.isValid()) {
return QSize(0, 0);
}
const QString text = index.model()->data(index, Qt::DisplayRole).toString();
const QIcon icon = index.model()->data(index, Qt::DecorationRole).value<QIcon>();
const QPixmap pixmap = icon.pixmap(iconSize, iconSize);
QFontMetrics fm = option.fontMetrics;
int gap = fm.height();
#if QT_VERSION >= 0x050100
QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio();
#else
QSize layoutSize = pixmap.size();
#endif
if (layoutSize.height() == 0) {
/**
* No pixmap loaded yet, we'll use the default icon size in this case.
*/
layoutSize=QSize(iconSize, iconSize);
}
QTextLayout iconTextLayout(text, option.font);
int wt = layoutText(&iconTextLayout, qMax(3 * layoutSize.width(), 8 * fm.height()));
int ht = iconTextLayout.boundingRect().height();
int width, height;
if (text.isEmpty()) {
height = layoutSize.height();
} else {
height = layoutSize.height() + ht + 10;
}
width = qMax(wt, layoutSize.width()) + gap;
return QSize(width, height);
}
示例15: draw
void QGraphicsGlowEffect::draw(QPainter* painter) {
QPoint offset;
QPixmap source = sourcePixmap(Qt::LogicalCoordinates, &offset);
source = source.scaled(source.size().width()/source.devicePixelRatio(), source.size().height()/source.devicePixelRatio());
QPixmap glow;
QGraphicsColorizeEffect *colorize = new QGraphicsColorizeEffect;
colorize->setColor(_color);
colorize->setStrength(1);
glow = applyEffectToPixmap(source, colorize, 0);
QGraphicsBlurEffect *blur = new QGraphicsBlurEffect;
blur->setBlurRadius(_blurRadius);
glow = applyEffectToPixmap(glow, blur, _extent);
for (int i = 0; i < _strength; i++)
painter->drawPixmap(offset - QPoint(_extent, _extent), glow);
drawSource(painter);
}