0
在我自定義的QWidget paintEvent方法中,我想繪製一個帶有圓形圖像圖標的圓。源圖像從文件加載,然後使用QPainter組合自動轉換爲圓形。怎麼做?謝謝!如何從圖像文件創建圓形圖標?
void DotGraphView::paintNodes(QPainter & painter)
{
painter.setPen(Qt::blue);
painter.drawEllipse(x, y, 36, 36);
QPixmap icon("./image.png");
QImage fixedImage(64, 64, QImage::Format_ARGB32_Premultiplied);
QPainter imgPainter(&fixedImage);
imgPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
imgPainter.drawPixmap(0, 0, 64, 64, icon);
imgPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
imgPainter.setBrush(Qt::transparent);
imgPainter.drawEllipse(32, 32, 30, 30);
imgPainter.end();
painter.drawPixmap(x, y, 64, 64, QPixmap::fromImage(fixedImage));
}
上述代碼不起作用。輸出顯示不是圓形圖像。
請詳細說明它是如何工作的。它是否編譯?它可以運行嗎?它會產生錯誤的輸出嗎?以何種方式? – 2012-01-01 14:40:58
輸出顯示不是圓形圖像。 – allenchen 2012-01-01 14:47:14
究竟是什麼?你可以上傳截圖嗎? – Cydonia7 2012-01-01 14:56:14