本文整理汇总了C++中QBitmap::rect方法的典型用法代码示例。如果您正苦于以下问题:C++ QBitmap::rect方法的具体用法?C++ QBitmap::rect怎么用?C++ QBitmap::rect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBitmap
的用法示例。
在下文中一共展示了QBitmap::rect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void rectangle::paintEvent(QPaintEvent *)
{
QBitmap bmp (this->rect().width(), this->height());
QPainter paint(&bmp);
QPen pen(Qt::black);
pen.setWidth(4);
paint.setPen(pen);
paint.setBrush(Qt::white);
paint.drawRect(1,1,bmp.rect().width()-2, bmp.rect().height()-2);
this->setMask(bmp);
bmp.save("c:/1.bmp");
}
示例2: pinRect
//!
//! Constructor of the ParameterTypeIcon class.
//!
//! \param color The color for the parameter type icon.
//!
ParameterTypeIcon::ParameterTypeIcon ( const QColor &color )
{
m_color = color;
const QRect pinRect (0, 4, 15, 8);
const QColor penColor (109, 109, 109);
QPixmap normalPixmap (16, 16);
QPainter painter;
if (painter.begin(&normalPixmap)) {
// get the background color from the application style's standard palette
QColor backgroundColor = QApplication::style()->standardPalette().color(QPalette::Base);
// fill the pixmap with the background color
painter.fillRect(normalPixmap.rect(), QBrush(backgroundColor));
// draw the pin rect into the pixmap
painter.setPen(QPen(penColor));
painter.setBrush(QBrush(m_color));
painter.drawRoundRect(pinRect);
// end painting the pixmap
if (painter.end()) {
// create a bitmap for masking the pixmap
QBitmap maskBitmap (normalPixmap.size());
if (painter.begin(&maskBitmap)) {
// fill the bitmap with white (meaning transparent)
painter.fillRect(maskBitmap.rect(), QBrush(QColor(Qt::white)));
// draw the pin rect as black (meaning opaque)
painter.setPen(QPen(QColor(Qt::black)));
painter.setBrush(QBrush(QColor(Qt::black)));
painter.drawRoundRect(pinRect);
// end painting the bitmap and set it as mask for the pixmap
if (painter.end())
normalPixmap.setMask(maskBitmap);
}
}
}
// add the pixmap to the icon
addPixmap(normalPixmap);
}
示例3: paint
void QWaylandMaterialDecoration::paint(QPaintDevice *device)
{
const QRect frameGeometry = window()->frameGeometry();
QRect top(QPoint(WINDOW_BORDER, WINDOW_BORDER), QSize(frameGeometry.width(), margins().top()));
QPainter p(device);
p.setRenderHint(QPainter::Antialiasing);
// Title bar
int radius = waylandWindow()->isMaximized() ? 0 : dp(3);
QPainterPath roundedRect;
roundedRect.addRoundedRect(0, 0, frameGeometry.width(), margins().top() * 1.5,
radius, radius);
p.fillPath(roundedRect.simplified(), m_backgroundColor);
// Borders
QPainterPath borderPath;
borderPath.addRect(0, margins().top(), margins().left(), frameGeometry.height() - margins().top());
borderPath.addRect(0, frameGeometry.height() - margins().bottom(), frameGeometry.width(), margins().bottom());
borderPath.addRect(frameGeometry.width() - margins().right(), margins().top(), margins().right(), frameGeometry.height() - margins().bottom());
p.fillPath(borderPath, m_backgroundColor);
// Window title
QString windowTitleText = window()->title();
if (!windowTitleText.isEmpty()) {
if (m_windowTitle.text() != windowTitleText) {
m_windowTitle.setText(windowTitleText);
m_windowTitle.prepare();
}
QRect titleBar = top;
titleBar.setLeft(margins().left() + BUTTON_SPACING);
titleBar.setRight(minimizeButtonRect().left() - BUTTON_SPACING);
p.save();
p.setClipRect(titleBar);
p.setPen(m_textColor);
QSizeF size = m_windowTitle.size();
int dx = (top.width() - size.width()) / 2;
int dy = (top.height() - size.height()) / 2;
QFont font = p.font();
font.setBold(true);
font.setFamily("Roboto");
p.setFont(font);
QPoint windowTitlePoint(top.topLeft().x() + dx, top.topLeft().y() + dy);
p.drawStaticText(windowTitlePoint, m_windowTitle);
p.restore();
}
p.save();
p.setPen(m_iconColor);
// Close button
QBitmap closeIcon = buttonIcon("window-close");
p.drawPixmap(closeButtonRect(), closeIcon, closeIcon.rect());
// Maximize button
if (window()->flags() & Qt::WindowMaximizeButtonHint) {
QBitmap maximizeIcon =
buttonIcon(waylandWindow()->isMaximized() ? "window-restore" : "window-maximize");
p.drawPixmap(maximizeButtonRect(), maximizeIcon, maximizeIcon.rect());
}
// Minimize button
if (window()->flags() & Qt::WindowMinimizeButtonHint) {
QBitmap minimizeIcon = buttonIcon("window-minimize");
p.drawPixmap(minimizeButtonRect(), minimizeIcon, minimizeIcon.rect());
}
p.restore();
}
示例4: paint
void QWaylandMaterialDecoration::paint(QPaintDevice *device)
{
QRect surfaceRect(QPoint(), window()->frameGeometry().size());
QRect top(QPoint(), QSize(window()->frameGeometry().width(), margins().top()));
QPainter p(device);
p.setRenderHint(QPainter::Antialiasing);
// Title bar
int radius = waylandWindow()->isMaximized() ? 0 : dp(3);
QPainterPath roundedRect;
roundedRect.addRoundedRect(0, 0, window()->frameGeometry().width(), margins().top() * 1.5,
radius, radius);
p.fillPath(roundedRect.simplified(), m_backgroundColor);
// Window icon
QIcon icon = waylandWindow()->windowIcon();
if (!icon.isNull()) {
QPixmap pixmap = icon.pixmap(QSize(128, 128));
QPixmap scaled = pixmap.scaled(22, 22, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
QRectF iconRect(0, 0, 22, 22);
p.drawPixmap(iconRect.adjusted(margins().left() + BUTTON_SPACING, 4,
margins().left() + BUTTON_SPACING, 4),
scaled, iconRect);
}
// Window title
QString windowTitleText = window()->title();
if (!windowTitleText.isEmpty()) {
if (m_windowTitle.text() != windowTitleText) {
m_windowTitle.setText(windowTitleText);
m_windowTitle.prepare();
}
QRect titleBar = top;
titleBar.setLeft(margins().left() + BUTTON_SPACING +
(icon.isNull() ? 0 : 22 + BUTTON_SPACING));
titleBar.setRight(minimizeButtonRect().left() - BUTTON_SPACING);
p.save();
p.setClipRect(titleBar);
p.setPen(m_textColor);
QSizeF size = m_windowTitle.size();
int dx = (top.width() - size.width()) / 2;
int dy = (top.height() - size.height()) / 2;
QFont font = p.font();
font.setBold(true);
font.setFamily("Roboto");
p.setFont(font);
QPoint windowTitlePoint(top.topLeft().x() + dx, top.topLeft().y() + dy);
p.drawStaticText(windowTitlePoint, m_windowTitle);
p.restore();
}
p.save();
p.setPen(m_iconColor);
// Close button
QBitmap closeIcon = buttonIcon("window-close");
p.drawPixmap(closeButtonRect(), closeIcon, closeIcon.rect());
// Maximize button
QBitmap maximizeIcon =
buttonIcon(waylandWindow()->isMaximized() ? "window-restore" : "window-maximize");
p.drawPixmap(maximizeButtonRect(), maximizeIcon, maximizeIcon.rect());
// Minimize button
QBitmap minimizeIcon = buttonIcon("window-minimize");
p.drawPixmap(minimizeButtonRect(), minimizeIcon, minimizeIcon.rect());
p.restore();
}