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. How to resize and make the new size persistent in QSvgWidget?
Forum Updated to NodeBB v4.3 + New Features

How to resize and make the new size persistent in QSvgWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 490 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.
  • D Offline
    D Offline
    deleted385
    wrote on last edited by deleted385
    #1

    It's a continuation of this post. With that approach when I resize the pixmap, it gets pixelated so I've converted that into a QSvgWidget like this:

    ActionButton::ActionButton(const QString &fileName, QWidget *parent) : QSvgWidget(parent){
        QFile f(fileName);
        f.open(QIODevice::ReadOnly | QIODevice::Text);
        m_document.setContent(f.readAll()); //QDomDocument m_document;
        changeColor(Qt::black);
    }
    void ActionButton::enterEvent(QEnterEvent*){ changeColor(Qt::blue); }
    void ActionButton::leaveEvent(QEvent*){ changeColor(Qt::black);}
    void ActionButton::mousePressEvent(QMouseEvent*){ changeColor(Qt::red); }
    void ActionButton::mouseReleaseEvent(QMouseEvent*){ emit triggered(); }
    void ActionButton::changeColor(const QColor &color){
        m_document.elementsByTagName("path").at(0).toElement().setAttribute("fill", color.name());
        resize(QSize(14, 14));
        renderer()->load(m_document.toByteArray());
    }
    

    and this is what I get with those;

    x1.gif

    initially, those icons were not resized although I've a changeColor(Qt::black) call in the constructor. Later when I hover over those icons, they're resized. How to get those resized when they're displayed/rendered first? Is it possible to make the new size persistent and avoid resize(QSize(14, 14)) call in changeColor function?

    D 1 Reply Last reply
    0
    • D deleted385

      It's a continuation of this post. With that approach when I resize the pixmap, it gets pixelated so I've converted that into a QSvgWidget like this:

      ActionButton::ActionButton(const QString &fileName, QWidget *parent) : QSvgWidget(parent){
          QFile f(fileName);
          f.open(QIODevice::ReadOnly | QIODevice::Text);
          m_document.setContent(f.readAll()); //QDomDocument m_document;
          changeColor(Qt::black);
      }
      void ActionButton::enterEvent(QEnterEvent*){ changeColor(Qt::blue); }
      void ActionButton::leaveEvent(QEvent*){ changeColor(Qt::black);}
      void ActionButton::mousePressEvent(QMouseEvent*){ changeColor(Qt::red); }
      void ActionButton::mouseReleaseEvent(QMouseEvent*){ emit triggered(); }
      void ActionButton::changeColor(const QColor &color){
          m_document.elementsByTagName("path").at(0).toElement().setAttribute("fill", color.name());
          resize(QSize(14, 14));
          renderer()->load(m_document.toByteArray());
      }
      

      and this is what I get with those;

      x1.gif

      initially, those icons were not resized although I've a changeColor(Qt::black) call in the constructor. Later when I hover over those icons, they're resized. How to get those resized when they're displayed/rendered first? Is it possible to make the new size persistent and avoid resize(QSize(14, 14)) call in changeColor function?

      D Offline
      D Offline
      deleted385
      wrote on last edited by
      #2

      @Emon-Haque, took a while to figure out that setMaximumSize(QSize(14, 14)) is what I need in the constructor!

      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