From 3dd7233201e81a1446c3ba0874903762d5824bbe Mon Sep 17 00:00:00 2001 From: tianduanrui <2407223896@qq.com> Date: Sun, 29 Sep 2019 23:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E8=A7=84=E5=88=99label=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81scaledContent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exquisite/irregularwidgets/qqtirregularlabel.cpp | 11 +++++++++++ test/testirregularwidgets/mainwindow.cpp | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/exquisite/irregularwidgets/qqtirregularlabel.cpp b/src/exquisite/irregularwidgets/qqtirregularlabel.cpp index 7af87338..1ca19273 100644 --- a/src/exquisite/irregularwidgets/qqtirregularlabel.cpp +++ b/src/exquisite/irregularwidgets/qqtirregularlabel.cpp @@ -23,6 +23,17 @@ void QQtIrregularLabel::makeMaskWidget ( void ) if ( normalImage.isNull() ) return; //return QQtLabel::resizeEvent ( event ); + if ( hasScaledContents() ) + { + //zoom + setMask ( QPixmap::fromImage ( normalImage + .scaled ( rect().width(), rect().height(), Qt::IgnoreAspectRatio ) + ).mask() ); + + return; + + } + //label的特点, //图片无论如何不会缩放的 !!! //图片无论如何不会变形的 diff --git a/test/testirregularwidgets/mainwindow.cpp b/test/testirregularwidgets/mainwindow.cpp index c4958971..c21072b2 100644 --- a/test/testirregularwidgets/mainwindow.cpp +++ b/test/testirregularwidgets/mainwindow.cpp @@ -116,9 +116,12 @@ MainWindow::MainWindow ( QWidget* parent ) : ui->label_3->installEventFilter ( clicker ); ui->label_8->setPixmap ( QPixmap ( conf_root ( "a1.png" ) ) ); + //ui->label_8->setScaledContents ( true ); + //ui->label_8->setAutoFillBackground ( true ); ui->label_7->setPixmap ( QPixmap ( conf_root ( "a1.png" ) ) ); ui->label_7->installEventFilter ( clicker ); ui->label_7->installEventFilter ( this ); + //ui->label_7->setScaledContents ( true ); QStringList items; items << "Qt::AlignLeft"