Circle user avatar issue
-
wrote on 27 Jan 2018, 13:55 last edited by
Yes.
-
Yes.
@Cobra91151
Ok, then painting yourself seems better :)
What was wrong with the paintEvent + scaled + drawEllipse ?
since you are now looking into masks -
@Cobra91151
Ok, then painting yourself seems better :)
What was wrong with the paintEvent + scaled + drawEllipse ?
since you are now looking into maskswrote on 27 Jan 2018, 14:11 last edited byI draws the image but not rounds it.
void AccountImage::paintEvent(QPaintEvent *event) { QPixmap pixmap(":/Icon/default_avatar.png"); QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QBrush brush(scaled); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(brush); painter.drawPixmap(0, 0, scaled); QLabel::paintEvent(event); }
-
Why not ?
just need the
painter.drawEllipse(0, 0, scaled.width(), scaled.height());
after
painter.drawPixmap(0, 0, scaled); -
Why not ?
just need the
painter.drawEllipse(0, 0, scaled.width(), scaled.height());
after
painter.drawPixmap(0, 0, scaled);wrote on 27 Jan 2018, 14:13 last edited by Cobra91151drawPixmap
is draws the pixmap, not circle. What method I should use to get image circle? -
drawPixmap
is draws the pixmap, not circle. What method I should use to get image circle?@Cobra91151
as before. drawEllipse -
@Cobra91151
as before. drawEllipsewrote on 27 Jan 2018, 14:19 last edited by Cobra91151Code:
void AccountImage::paintEvent(QPaintEvent *event) { QPixmap pixmap(":/Icon/default_avatar.png"); QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QBrush brush(scaled); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(brush); painter.drawPixmap(0, 0, scaled); painter.drawEllipse(0, 0, scaled.width(), scaled.height()); QLabel::paintEvent(event); }
Still image is not fully in a circle.
Update:
It looks better here:void AccountImage::paintEvent(QPaintEvent *event) { QPixmap pixmap(":/Icon/default_avatar.png"); QBrush brush(pixmap); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(brush); painter.drawRoundedRect(0, 0, width(), height(), 100, 100); QLabel::paintEvent(event); }
But I can't scale it properly.
-
Hi
well can scale the image to less that the size of the
QLabel so there are room to draw a circle around the image.
Since the image is the size of the Label , you cant draw outside the image.so either make image smaller to it can be inside circle or
make image smaller so it fits in circle. -
Hi
well can scale the image to less that the size of the
QLabel so there are room to draw a circle around the image.
Since the image is the size of the Label , you cant draw outside the image.so either make image smaller to it can be inside circle or
make image smaller so it fits in circle.wrote on 27 Jan 2018, 14:42 last edited by Cobra91151So now it looks much better:
void AccountImage::paintEvent(QPaintEvent *event) { QPixmap pixmap(":/Icon/default_avatar.png"); QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QBrush brush(scaled); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(brush); painter.drawRoundedRect(0, 0, width(), height(), 100, 100); QLabel::paintEvent(event); }
-
So now it looks much better:
void AccountImage::paintEvent(QPaintEvent *event) { QPixmap pixmap(":/Icon/default_avatar.png"); QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QBrush brush(scaled); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(brush); painter.drawRoundedRect(0, 0, width(), height(), 100, 100); QLabel::paintEvent(event); }
@Cobra91151
Ah yes. Like brush.
So you want image to be inside the circle and let it clip anything else.
I thought you wanted to paint a circle on it. :) -
@Cobra91151
Ah yes. Like brush.
So you want image to be inside the circle and let it clip anything else.
I thought you wanted to paint a circle on it. :)wrote on 27 Jan 2018, 15:10 last edited by Cobra91151So finally I have set it properly and it works great!
void AccountImage::paintEvent(QPaintEvent *event) { QPixmap pixmap(":/Icon/my_avatar.png"); QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); QBrush brush(scaled); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(brush); painter.drawRoundedRect(0, 0, width(), height(), 100, 100); QLabel::paintEvent(event); }
Result:
Thank you for the help.
27/28