本文整理汇总了C++中QPixmap::setBrush方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::setBrush方法的具体用法?C++ QPixmap::setBrush怎么用?C++ QPixmap::setBrush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::setBrush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
/** Handle paintEvent (ie. animate icon) */
void TopLevel::paintEvent(QPaintEvent *)
{
QPixmap *pm = &mugPixmap;
if (running) {
if (useTrayVis)
pm = &teaAnim1Pixmap; // this is 'mugPixmap' plus brown content
else
pm = &teaNotReadyPixmap; // generic "steeping" icon
} else {
// use simple two-frame "animation"
// FIXME: how about using a QMovie instead? (eg. MNG)
if (ready) {
if (firstFrame)
pm = &teaAnim1Pixmap;
else
pm = &teaAnim2Pixmap;
}
}
// overlay pie chart onto tray icon
QPixmap base(*pm); // make copy of base pixmap
if (useTrayVis && running) {
// extend mask
QBitmap mask = *(base.mask());
QPainter pm(&mask);
pm.setBrush(Qt::color1); // fill with "foreground-colour"
pm.setPen(Qt::NoPen); // no border needed/wanted
pm.drawPie(0+1, 9+1, 11, 11, 90*16, -360*16); // full circle of small size
pm.drawPie(0, 9, 13, 13, 90*16, percentDone*16); // pie part of big size
pm.end();
base.setMask(mask);
// draw pie chart
QPainter px(&base);
px.setPen(QPen(Qt::black, 0)); // black border
px.setBrush(QColor(192, 0, 0)); // red fill colour for small circle
px.drawPie(0+1, 9+1, 11, 11, 90*16, -360*16);
px.setBrush(QColor(0, 192, 0)); // green fill colour for pie part
px.drawPie(0, 9, 13, 13, 90*16, percentDone*16);
px.end();
}
// FIXME: over-emphasize first and last few percent? (for better visibility)
// FIXME: some optimizations (eg. store pre-drawn QPixmap with small circle)
// (and use drawEllipse() instead of drawPie() for small circle!)
// set new tray icon
QPainter p(this);
int x = 1 + (12 - pm->width()/2);
int y = 1 + (12 - pm->height()/2);
p.drawPixmap(x, y, base);
p.end();
}