There is a QLabel in which you need to push the image. It is necessary to make so that this image was displayed with a frame of various thickness. How can I do that?
PS QtStyleSheets not suitable

Or, if there is a better way to work with images in Qt , please tell me. To make the task clearer, you need to render an HTML img tag with its attributes using Qt Widgets . I know very little Qt , and time is running out.

    1 answer 1

    The QLabel class is inherited from QFrame , and the latter has methods for setting the frame , the style of the shadow , and the thickness of the lines ( here and here ).

    But you can manually on the widget by overriding the corresponding method:

     void MyWidget::paintEvent(QPaintEvent *event) { QPixmap pix("image.png"); if(pix.isNull() == false) { QRect dst_rc = rect(); if(dst_rc.width() > dst_rc.height()) pix = pix.scaledToHeight(dst_rc.height()); else if(dst_rc.height() > dst_rc.width()) pix = pix.scaledToWidth(dst_rc.width()); dst_rc = pix.rect(); dst_rc.moveCenter(rect().center()); const QBrush brush(Qt::black); const QPen pen(brush, 2); // Второй аргумент - толщина линии. QPainter painter(this); painter.setPen(pen); painter.setBrush(brush); painter.drawPixmap(dst_rc, pix); painter.drawRect(dst_rc); } event->accept(); } 

    ... where MyWidget is a QWidget descendant.