superpacko
18th November 2011, 19:43
Hey there!
Im building a QGridLayout that will display images (loaded from id3Tags) in each cell. Right now im using QLabels or QWidgets to wrap the image in a QPixmap.
The problem that i have is that the images are rectangles and i want them to be displayed with nice and smooth rounded corners.
How could i accomplish that?
I've tried creating a custom widget that would paint a rounded rectangle and then paint a pixmap, but the pixmap doesnt get rounded.
Then i found that i can set a mask on the pixmap, so i think i could set a mask with rounded corners, but dont know how to do that rounded qbitmap.
what i tried:
void RoundedCover::paintEvent(QPaintEvent *)
{
QRectF rect(0,0,150,150);
QPainter painter(this);
painter.drawPixmap(0,0, _pixmap);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setWorldMatrixEnabled(false);
painter.setPen(QPen( QBrush(QColor("darkgrey"), Qt::SolidPattern), 2.0));
painter.drawRoundedRect(rect, 20.0, 15.0);
}
I thought about something like...
void RoundedCover::paintEvent(QPaintEvent *)
{
QRectF rect(0,0,150,150);
QPainter painter(this);
_pixmap.setMask(....);//Something here to make it rounded
painter.drawPixmap(0,0, _pixmap);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setWorldMatrixEnabled(false);
painter.setPen(QPen( QBrush(QColor("darkgrey"), Qt::SolidPattern), 2.0));
painter.drawRoundedRect(rect, 20.0, 15.0);
}
any ideas?
thanks!
Im building a QGridLayout that will display images (loaded from id3Tags) in each cell. Right now im using QLabels or QWidgets to wrap the image in a QPixmap.
The problem that i have is that the images are rectangles and i want them to be displayed with nice and smooth rounded corners.
How could i accomplish that?
I've tried creating a custom widget that would paint a rounded rectangle and then paint a pixmap, but the pixmap doesnt get rounded.
Then i found that i can set a mask on the pixmap, so i think i could set a mask with rounded corners, but dont know how to do that rounded qbitmap.
what i tried:
void RoundedCover::paintEvent(QPaintEvent *)
{
QRectF rect(0,0,150,150);
QPainter painter(this);
painter.drawPixmap(0,0, _pixmap);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setWorldMatrixEnabled(false);
painter.setPen(QPen( QBrush(QColor("darkgrey"), Qt::SolidPattern), 2.0));
painter.drawRoundedRect(rect, 20.0, 15.0);
}
I thought about something like...
void RoundedCover::paintEvent(QPaintEvent *)
{
QRectF rect(0,0,150,150);
QPainter painter(this);
_pixmap.setMask(....);//Something here to make it rounded
painter.drawPixmap(0,0, _pixmap);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setWorldMatrixEnabled(false);
painter.setPen(QPen( QBrush(QColor("darkgrey"), Qt::SolidPattern), 2.0));
painter.drawRoundedRect(rect, 20.0, 15.0);
}
any ideas?
thanks!