Skip to content

Commit fa5749c

Browse files
committed
qt, refactor: Fix 'pixmap is deprecated' warnings
1 parent b02264c commit fa5749c

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ void BitcoinGUI::updateProxyIcon()
13051305
bool proxy_enabled = clientModel->getProxyInfo(ip_port);
13061306

13071307
if (proxy_enabled) {
1308-
if (labelProxyIcon->pixmap() == nullptr) {
1308+
if (!GUIUtil::HasPixmap(labelProxyIcon)) {
13091309
QString ip_port_q = QString::fromStdString(ip_port);
13101310
labelProxyIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/proxy").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
13111311
labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q));

src/qt/guiutil.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,4 +929,26 @@ QDateTime StartOfDay(const QDate& date)
929929
#endif
930930
}
931931

932+
bool HasPixmap(const QLabel* label)
933+
{
934+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
935+
return !label->pixmap(Qt::ReturnByValue).isNull();
936+
#else
937+
return label->pixmap() != nullptr;
938+
#endif
939+
}
940+
941+
QImage GetImage(const QLabel* label)
942+
{
943+
if (!HasPixmap(label)) {
944+
return QImage();
945+
}
946+
947+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
948+
return label->pixmap(Qt::ReturnByValue).toImage();
949+
#else
950+
return label->pixmap()->toImage();
951+
#endif
952+
}
953+
932954
} // namespace GUIUtil

src/qt/guiutil.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ namespace GUIUtil
312312
*/
313313
QDateTime StartOfDay(const QDate& date);
314314

315+
/**
316+
* Returns true if pixmap has been set.
317+
*
318+
* QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.
319+
*/
320+
bool HasPixmap(const QLabel* label);
321+
QImage GetImage(const QLabel* label);
322+
315323
} // namespace GUIUtil
316324

317325
#endif // BITCOIN_QT_GUIUTIL_H

src/qt/qrimagewidget.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,12 @@ bool QRImageWidget::setQR(const QString& data, const QString& text)
9595

9696
QImage QRImageWidget::exportImage()
9797
{
98-
if(!pixmap())
99-
return QImage();
100-
return pixmap()->toImage();
98+
return GUIUtil::GetImage(this);
10199
}
102100

103101
void QRImageWidget::mousePressEvent(QMouseEvent *event)
104102
{
105-
if(event->button() == Qt::LeftButton && pixmap())
106-
{
103+
if (event->button() == Qt::LeftButton && GUIUtil::HasPixmap(this)) {
107104
event->accept();
108105
QMimeData *mimeData = new QMimeData;
109106
mimeData->setImageData(exportImage());
@@ -118,7 +115,7 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event)
118115

119116
void QRImageWidget::saveImage()
120117
{
121-
if(!pixmap())
118+
if (!GUIUtil::HasPixmap(this))
122119
return;
123120
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), nullptr);
124121
if (!fn.isEmpty())
@@ -129,14 +126,14 @@ void QRImageWidget::saveImage()
129126

130127
void QRImageWidget::copyImage()
131128
{
132-
if(!pixmap())
129+
if (!GUIUtil::HasPixmap(this))
133130
return;
134131
QApplication::clipboard()->setImage(exportImage());
135132
}
136133

137134
void QRImageWidget::contextMenuEvent(QContextMenuEvent *event)
138135
{
139-
if(!pixmap())
136+
if (!GUIUtil::HasPixmap(this))
140137
return;
141138
contextMenu->exec(event->globalPos());
142139
}

0 commit comments

Comments
 (0)