Есть класс
Код: Выделить всё
class DrawWidget : public QWidget
{
Q_OBJECT
public:
explicit DrawWidget(QWidget *parent = nullptr) :
QWidget(parent)
{
setFixedSize(500, 500);
int w = 200;
int h = 100;
//создаем маску
QPainterPath m_path;
m_path.moveTo(0, h / 2);
m_path.lineTo(w, h);
m_path.lineTo(w, 0);
m_path.lineTo(0, h / 2);
QPixmap *b_mask = new QPixmap(w, h);
QPainter p_mask(b_mask);
p_mask.fillRect(0, 0, w, h, QColor(Qt::color0));
p_mask.fillPath(m_path, QBrush(Qt::color1));
QBitmap bitmap(w, h);
QPainter p_bitmap(&bitmap);
p_bitmap.fillRect(0, 0, w, h, QColor(Qt::color0));
p_bitmap.fillPath(m_path, QBrush(Qt::color1));
//bitmap.save("/dev/shm/bitmap.png", "PNG");
pixmap = new QPixmap(w, h);
QPainter p(pixmap);
//pixmap->setMask(mask->mask());
//pixmap->setMask(bitmap);
p.fillRect(0, 0, w, h, QColor(Qt::blue));
//pixmap->setMask(b_mask->scaled(w, h).mask());
pixmap->setMask(b_mask->mask());
//pixmap->setMask(bitmap);
}
private:
QPixmap *pixmap = nullptr;
protected:
void paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.fillRect(0, 0, width(), height(), QColor(Qt::green));
painter.save();
painter.translate(250, 250);
//for(int n=0; n<8; n++)
{
painter.drawPixmap(0, -50, *pixmap);
painter.rotate(45.0);
}
painter.restore();
}
};
Почему?