Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSvgWidget in QGridLayout
Forum Updated to NodeBB v4.3 + New Features

QSvgWidget in QGridLayout

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 249 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    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.

    Kind Regards,
    Sy

    SPlattenS 1 Reply Last reply
    0
    • SPlattenS SPlatten

      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.

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #2

      @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!

      Kind Regards,
      Sy

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved