qpixmap을 사용하여 qlabel 크기를 조정할 때 비슷한 문제가 발생했습니다. 가장 잘 작동하는 메서드는 대신 QWidget을 사용하고 paintEvent 함수를 다시 구현하는 것입니다. 그런 다음 QWidget 이미지의 크기가 조정되면 자동으로 크기가 조절됩니다.
bool image_set_;
QImage image_;
QBrush paintbrush_;
void MyClass::paintEvent(QPaintEvent* event)
{
// if the QWidget has an image set, then we use our custom painting.
if(this->private_->image_set_)
{
//I've made it so that my QWidget has a 1px white border
this->private_->paintbrush_.setTextureImage(this->private_->image_.scaled(QSize(this->width() - 2, this->height() - 2)));
QPainter painter(this);
QRect temp_rect = QRect(1, 1, this->width()-2, this->height() - 2);
painter.fillRect(this->rect(), Qt::white);
painter.fillRect(temp_rect, this->private_->paintbrush_);
}
else
{
QWidget::paintEvent(event);
}
}
: 나는 private_라는 개인 객체의 private 변수를 가지고 내 경우
예를 들면 다음과 같습니다