Examples: Replace deprecated QLabel API
Task-number: QTBUG-48701 Change-Id: I6fc875a35dfc3bf4d906d0f0e495c18ef566d1e1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
parent
967e55a628
commit
b90eaa3bb5
@ -109,7 +109,7 @@ void Screenshot::resizeEvent(QResizeEvent * /* event */)
|
|||||||
{
|
{
|
||||||
QSize scaledSize = originalPixmap.size();
|
QSize scaledSize = originalPixmap.size();
|
||||||
scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
|
scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
|
||||||
if (!screenshotLabel->pixmap() || scaledSize != screenshotLabel->pixmap()->size())
|
if (scaledSize != screenshotLabel->pixmap(Qt::ReturnByValue).size())
|
||||||
updateScreenshotLabel();
|
updateScreenshotLabel();
|
||||||
}
|
}
|
||||||
//! [1]
|
//! [1]
|
||||||
|
@ -175,8 +175,8 @@
|
|||||||
will expand to
|
will expand to
|
||||||
|
|
||||||
\code
|
\code
|
||||||
if (!imageLabel->pixmap())
|
if (imageLabel->pixmap(Qt::ReturnByValue).isNull())
|
||||||
qFatal("ASSERT: "imageLabel->pixmap()" in file ...");
|
qFatal("ASSERT: "imageLabel->pixmap(Qt::ReturnByValue).isNull()" in file ...");
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
In release mode, the macro simply disappear. The mode can be set
|
In release mode, the macro simply disappear. The mode can be set
|
||||||
|
@ -142,7 +142,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
if (!child)
|
if (!child)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPixmap pixmap = *child->pixmap();
|
QPixmap pixmap = child->pixmap(Qt::ReturnByValue);
|
||||||
|
|
||||||
QByteArray itemData;
|
QByteArray itemData;
|
||||||
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
||||||
|
@ -208,7 +208,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
//! [16]
|
//! [16]
|
||||||
QDrag *drag = new QDrag(this);
|
QDrag *drag = new QDrag(this);
|
||||||
drag->setMimeData(mimeData);
|
drag->setMimeData(mimeData);
|
||||||
drag->setPixmap(*child->pixmap());
|
drag->setPixmap(child->pixmap(Qt::ReturnByValue));
|
||||||
drag->setHotSpot(hotSpot);
|
drag->setHotSpot(hotSpot);
|
||||||
|
|
||||||
child->hide();
|
child->hide();
|
||||||
|
@ -200,19 +200,20 @@ void ImageViewer::saveAs()
|
|||||||
void ImageViewer::print()
|
void ImageViewer::print()
|
||||||
//! [5] //! [6]
|
//! [5] //! [6]
|
||||||
{
|
{
|
||||||
Q_ASSERT(imageLabel->pixmap());
|
Q_ASSERT(!imageLabel->pixmap(Qt::ReturnByValue).isNull());
|
||||||
#if QT_CONFIG(printdialog)
|
#if QT_CONFIG(printdialog)
|
||||||
//! [6] //! [7]
|
//! [6] //! [7]
|
||||||
QPrintDialog dialog(&printer, this);
|
QPrintDialog dialog(&printer, this);
|
||||||
//! [7] //! [8]
|
//! [7] //! [8]
|
||||||
if (dialog.exec()) {
|
if (dialog.exec()) {
|
||||||
QPainter painter(&printer);
|
QPainter painter(&printer);
|
||||||
|
QPixmap pixmap = imageLabel->pixmap(Qt::ReturnByValue);
|
||||||
QRect rect = painter.viewport();
|
QRect rect = painter.viewport();
|
||||||
QSize size = imageLabel->pixmap()->size();
|
QSize size = pixmap.size();
|
||||||
size.scale(rect.size(), Qt::KeepAspectRatio);
|
size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||||
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||||
painter.setWindow(imageLabel->pixmap()->rect());
|
painter.setWindow(pixmap.rect());
|
||||||
painter.drawPixmap(0, 0, *imageLabel->pixmap());
|
painter.drawPixmap(0, 0, pixmap);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -383,9 +384,8 @@ void ImageViewer::updateActions()
|
|||||||
void ImageViewer::scaleImage(double factor)
|
void ImageViewer::scaleImage(double factor)
|
||||||
//! [23] //! [24]
|
//! [23] //! [24]
|
||||||
{
|
{
|
||||||
Q_ASSERT(imageLabel->pixmap());
|
|
||||||
scaleFactor *= factor;
|
scaleFactor *= factor;
|
||||||
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
|
imageLabel->resize(scaleFactor * imageLabel->pixmap(Qt::ReturnByValue).size());
|
||||||
|
|
||||||
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
|
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
|
||||||
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
|
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user