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. Qt5 - CPP - How to resize a QScrollList
Forum Updated to NodeBB v4.3 + New Features

Qt5 - CPP - How to resize a QScrollList

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

    I have the following problem.

    I have scroll list of widgets which is looking like this (if it's expended on X way too much)
    enter image description here

    If I will scale it on Y-axis it's going to look like this.

    enter image description here

    I'm trying to make those blue widgets to keep their aspect ratio, doesn't matter the size of the container. In order to do that I've reimplemented the resizeEvent like this:

    void PolygonButtonWidget::resizeEvent(QResizeEvent *event) {
        auto ratioW = 8;
        auto ratioH = 3;
        float thisAspectRatio = (float) event->size().width() / event->size().height();
        if (thisAspectRatio < ratioW / ratioH) {
            auto w = event->size().height() * ratioW / ratioH;
            auto h = event->size().height();
            qDebug() << hasHeightForWidth() << " " << w << " " << h;
    
            this->resize(w, h);
            if (m_nrButtons != 0) {
                this->move((w + 20) * m_nrButtons, this->y());
            }
        }
        QWidget::resizeEvent(event);
    }
    

    By doing this my list is going to look something like this

    enter image description here

    or like this

    enter image description here

    How can I fix this? For some reason, some of my widgets are going to disappear, what should be my approach in order to fix this issue?

    JonBJ 1 Reply Last reply
    0
    • V Vildnex

      I have the following problem.

      I have scroll list of widgets which is looking like this (if it's expended on X way too much)
      enter image description here

      If I will scale it on Y-axis it's going to look like this.

      enter image description here

      I'm trying to make those blue widgets to keep their aspect ratio, doesn't matter the size of the container. In order to do that I've reimplemented the resizeEvent like this:

      void PolygonButtonWidget::resizeEvent(QResizeEvent *event) {
          auto ratioW = 8;
          auto ratioH = 3;
          float thisAspectRatio = (float) event->size().width() / event->size().height();
          if (thisAspectRatio < ratioW / ratioH) {
              auto w = event->size().height() * ratioW / ratioH;
              auto h = event->size().height();
              qDebug() << hasHeightForWidth() << " " << w << " " << h;
      
              this->resize(w, h);
              if (m_nrButtons != 0) {
                  this->move((w + 20) * m_nrButtons, this->y());
              }
          }
          QWidget::resizeEvent(event);
      }
      

      By doing this my list is going to look something like this

      enter image description here

      or like this

      enter image description here

      How can I fix this? For some reason, some of my widgets are going to disappear, what should be my approach in order to fix this issue?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Vildnex said in Qt5 - CPP - How to resize a QScrollList:
      I don't know about the answer you are seeking, but while you are waiting for someone else to answer:

      auto ratioW = 8;
      auto ratioH = 3;
      float thisAspectRatio = (float) event->size().width() / event->size().height();
      if (thisAspectRatio < ratioW / ratioH) {
      

      That ratioW / ratioH looks like an integer division to me?

      1 Reply Last reply
      2

      • Login

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