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. Adjust QListWidget contents to adjust to Dialog size
Forum Updated to NodeBB v4.3 + New Features

Adjust QListWidget contents to adjust to Dialog size

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

    I have a QListWidget in a QDialog. It has the capability of displaying up to 511 items. I have added a QVBoxLayout and QHBoxLayout so when I adjust the dialog size it seems to adjust the QListWidget size, but the contents don't adjust. Adjusting the vertical size should create more columns. Adjusting Horizontally justs changes what can be visually seen. I have attached the code I am using, and I am using Qt6.

    #ifndef SO_REPORT_H
    #define SO_REPORT_H
    
    #include <QDialog>
    #include <QListWidget>
    #include <QVBoxLayout>
    #include <QScrollArea>
    
    #include "pcmission.h"
    
    class SO_Report : public QDialog
    {
    public:
        SO_Report(PcMission* pGlobal, QWidget* parent = nullptr);
    
    private:
        PcMission* m_pGlobal;
    
        int32_t Idx;
    };
    
    #endif // SO_REPORT_H
    
    
    #include "so_report.h"
    
    SO_Report::SO_Report(PcMission* pGlobal, QWidget* parent )
        : QDialog ( parent )
    {
        m_pGlobal = pGlobal;
    
        setWindowTitle("Options");
    
        QListWidget* soReport = new QListWidget();
        soReport->setSizeAdjustPolicy(QListWidget::AdjustToContents);
    
        QVBoxLayout* listLayout = new QVBoxLayout();
        listLayout->addWidget( soReport );
    
        QHBoxLayout* mainLayout = new QHBoxLayout(this);
        mainLayout->addLayout(listLayout);
    
        QString dataString;
    
        for(Idx = 0; Idx < m_pGlobal->validSOs.so_count; Idx++)
        {
            if( Idx < 9 )
            {
                dataString = "  ";
            }
            else if( Idx < 99 )
            {
                dataString = " ";
            }
    
            dataString += m_pGlobal->validSOs.Option[Idx].so +
                ". " + m_pGlobal->validSOs.Option[Idx].ao +
                "/" + m_pGlobal->validSOs.Option[Idx].cc;
    
            if( !m_pGlobal->validSOs.Option[Idx].wh.isEmpty() )
            {
                dataString += m_pGlobal->validSOs.Option[Idx].wh;
            }
    
            QListWidgetItem* soList = new QListWidgetItem ( dataString );
            soReport->addItem( soList );
        }
    }
    
    Pl45m4P 1 Reply Last reply
    0
    • G gabello306

      I have a QListWidget in a QDialog. It has the capability of displaying up to 511 items. I have added a QVBoxLayout and QHBoxLayout so when I adjust the dialog size it seems to adjust the QListWidget size, but the contents don't adjust. Adjusting the vertical size should create more columns. Adjusting Horizontally justs changes what can be visually seen. I have attached the code I am using, and I am using Qt6.

      #ifndef SO_REPORT_H
      #define SO_REPORT_H
      
      #include <QDialog>
      #include <QListWidget>
      #include <QVBoxLayout>
      #include <QScrollArea>
      
      #include "pcmission.h"
      
      class SO_Report : public QDialog
      {
      public:
          SO_Report(PcMission* pGlobal, QWidget* parent = nullptr);
      
      private:
          PcMission* m_pGlobal;
      
          int32_t Idx;
      };
      
      #endif // SO_REPORT_H
      
      
      #include "so_report.h"
      
      SO_Report::SO_Report(PcMission* pGlobal, QWidget* parent )
          : QDialog ( parent )
      {
          m_pGlobal = pGlobal;
      
          setWindowTitle("Options");
      
          QListWidget* soReport = new QListWidget();
          soReport->setSizeAdjustPolicy(QListWidget::AdjustToContents);
      
          QVBoxLayout* listLayout = new QVBoxLayout();
          listLayout->addWidget( soReport );
      
          QHBoxLayout* mainLayout = new QHBoxLayout(this);
          mainLayout->addLayout(listLayout);
      
          QString dataString;
      
          for(Idx = 0; Idx < m_pGlobal->validSOs.so_count; Idx++)
          {
              if( Idx < 9 )
              {
                  dataString = "  ";
              }
              else if( Idx < 99 )
              {
                  dataString = " ";
              }
      
              dataString += m_pGlobal->validSOs.Option[Idx].so +
                  ". " + m_pGlobal->validSOs.Option[Idx].ao +
                  "/" + m_pGlobal->validSOs.Option[Idx].cc;
      
              if( !m_pGlobal->validSOs.Option[Idx].wh.isEmpty() )
              {
                  dataString += m_pGlobal->validSOs.Option[Idx].wh;
              }
      
              QListWidgetItem* soList = new QListWidgetItem ( dataString );
              soReport->addItem( soList );
          }
      }
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @gabello306

      Set the resize policies of the headers/sections

      • https://doc.qt.io/qt-6/qlistview.html#ResizeMode-enum

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gabello306
        wrote on last edited by gabello306
        #3

        I entered the following code and it didn't do anything.

        soReport->setResizeMode(QListWidget::Adjust);
        
        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