QSvgWidget in QGridLayout
-
I want to use QSvgWidget in a QGridLayout, here is my code:
QGridLayout* pgrdloStatus(new QGridLayout); if ( mplblStsIcon == nullptr ) { mplblStsIcon = new QLabel(); } if ( mpsvgRxIcon == nullptr ) { mpsvgRxIcon = new QSvgWidget(":/SVG_LED"); } if ( mpsvgTxIcon == nullptr ) { mpsvgTxIcon = new QSvgWidget(":/SVG_LED"); } const QString cstrToolTip(QString( " Hostname: %1\r\nMAC address: %2") .arg(mstrHostname).arg(mstrMACaddress)); mplblStsIcon->setToolTip(cstrToolTip); pgrdloStatus->addWidget(mplblStsIcon, 0, 0, 1, 2, Qt::AlignHCenter); pgrdloStatus->addWidget(mpsvgRxIcon, 1, 0, 1, 1, Qt::AlignLeft); pgrdloStatus->addWidget(mpsvgTxIcon, 1, 1, 1, 1, Qt::AlignRight); return pgrdloStatus;This is a snippet from a function, I see the status icon at row 0 and column 0 which spans 2 columns this is fine, but I'm not seeing the SVG images.
I've add the SVG file to my resource file and have given it an alias of SVG_LED. If I double click the resource the SVG loads in Qt Creator, no problem.
-
I want to use QSvgWidget in a QGridLayout, here is my code:
QGridLayout* pgrdloStatus(new QGridLayout); if ( mplblStsIcon == nullptr ) { mplblStsIcon = new QLabel(); } if ( mpsvgRxIcon == nullptr ) { mpsvgRxIcon = new QSvgWidget(":/SVG_LED"); } if ( mpsvgTxIcon == nullptr ) { mpsvgTxIcon = new QSvgWidget(":/SVG_LED"); } const QString cstrToolTip(QString( " Hostname: %1\r\nMAC address: %2") .arg(mstrHostname).arg(mstrMACaddress)); mplblStsIcon->setToolTip(cstrToolTip); pgrdloStatus->addWidget(mplblStsIcon, 0, 0, 1, 2, Qt::AlignHCenter); pgrdloStatus->addWidget(mpsvgRxIcon, 1, 0, 1, 1, Qt::AlignLeft); pgrdloStatus->addWidget(mpsvgTxIcon, 1, 1, 1, 1, Qt::AlignRight); return pgrdloStatus;This is a snippet from a function, I see the status icon at row 0 and column 0 which spans 2 columns this is fine, but I'm not seeing the SVG images.
I've add the SVG file to my resource file and have given it an alias of SVG_LED. If I double click the resource the SVG loads in Qt Creator, no problem.
@SPlatten , fixed:
QGridLayout* pgrdloStatus(new QGridLayout); if ( mplblStsIcon == nullptr ) { mplblStsIcon = new QLabel(); } if ( mpsvgRxIcon == nullptr ) { mpsvgRxIcon = new QSvgWidget(":/SVG_LED"); mpsvgRxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mpsvgRxIcon->setFixedSize(TraineeMonitor::mscuintCommsIconWidth, TraineeMonitor::mscuintCommsIconHeight); } if ( mpsvgTxIcon == nullptr ) { mpsvgTxIcon = new QSvgWidget(":/SVG_LED"); mpsvgTxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mpsvgTxIcon->setFixedSize(TraineeMonitor::mscuintCommsIconWidth, TraineeMonitor::mscuintCommsIconHeight); } const QString cstrToolTip(QString( " Hostname: %1\r\nMAC address: %2") .arg(mstrHostname).arg(mstrMACaddress)); mplblStsIcon->setToolTip(cstrToolTip); pgrdloStatus->addWidget(mplblStsIcon, 0, 0, 1, 2, Qt::AlignHCenter); pgrdloStatus->addWidget(mpsvgRxIcon, 1, 0, 1, 1, Qt::AlignLeft); pgrdloStatus->addWidget(mpsvgTxIcon, 1, 1, 1, 1, Qt::AlignRight); return pgrdloStatus;Adding size policy fixes it, doh!