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. Failing to add a QListView inside a QWidget
Qt 6.11 is out! See what's new in the release blog

Failing to add a QListView inside a QWidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.9k 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.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    I am facing an issue related to displaying widgets. I have a QWidget inside which I wanna display a QListView. To illustrate further, here is the scenario:

    I have a QWidget which I am adding to a vertical layout first. Then I have a class ClipWidget which inherits from QWidget. By using QVBoxLayout, I am setting the layout of this Widget as follows:

    @QWidget *pListWidget = new QWidget(this);
    QWidget *pWidget = new QWidget(this);
    QVBoxLayout *playoutwid = new QVBoxLayout(pWidget);
    playoutwid->setSpacing(0);
    playoutwid->addWidget(pListWidget)
    
    m_pClipWidget = new ClipWidget(pListWidget);
    QWidget *pClip = new QWidget();
    QVBoxLayout *playout = new QVBoxLayout(pClip);
    playout->setSpacing(0);
    m_pClipWidget->setFixedHeight(120);
    m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
    playout->addWidget(m_pClipWidget)@
    

    If you notice, I am passing the QWidget object in my ClipWidget class as follows:

    @m_pClipWidget = new ClipWidget(pListWidget);@
    

    I have fixed the height of m_pClipWidget and I have set the width as expanding. With this my intention is to have this fixed m_pClipWidget inside a QWidget pListWidget.

    Now When I create an instance of ClipWidget, the constructor executes the following statements:

    @m_pSecondaryListView = new BinListView(this);
    QGridLayout *pgridlayout = new QGridLayout(this);  
    pgridlayout->addWidget(m_pSecondaryListView);@
    

    Here BinListView is a class which inherits from QListView. With this approach, I am looking forward to display ClipWidget inside the pListWidget but when I execute the code, it doesn't display.

    Ideally I should get a BinListView with the fixed height of 120 and expandable width inside a QWidget. Am I missing something???

    Please help :)

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Serenity
      wrote on last edited by
      #2

      Okay, first of all: Don't mix both!

      QListWidget is a simple version of QListView for people, who don't need the whole model/view functions or don't want to study that. So use QListView or QListWidget :)

      Both inherts QWidget (in any way) and can be added in a layout.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stoned Jesus
        wrote on last edited by
        #3

        Thanks Serenity.

        I understand what you are trying to say. Actually My intention is to use QWidget and let my ListView be inside it :)

        [quote author="Serenity" date="1361277884"]Okay, first of all: Don't mix both!

        QListWidget is a simple version of QListView for people, who don't need the whole model/view functions or don't want to study that. So use QListView or QListWidget :)

        Both inherts QWidget (in any way) and can be added in a layout.[/quote]

        --
        Thanks & Regards,
        Stoned Jesus

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Santosh Reddy
          wrote on last edited by
          #4

          You already have things, but not in proper place. Simply do like this

          @ClipWidget(QWidget * parent = 0)
          : QWidget(parent)
          {
          m_pSecondaryListView = new QListView(this);
          QGridLayout *pgridlayout = new QGridLayout(this);

          m_pSecondaryListView->setEditTriggers(QListView::NoEditTriggers);
          pgridlayout->addWidget(m_pSecondaryListView);
          

          }@

          @ClipWidget * m_pClipWidget = new ClipWidget();
          m_pClipWidget->setFixedHeight(120);
          m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
          m_pClipWidget->show();@

          SS

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stoned Jesus
            wrote on last edited by
            #5

            Thanks Santosh. But if you read the question, I want to add this "CLIPWIDGET" inside my QWidget "pListWidget". Your answer will display the ClipWidget with the fixed height oly.

            [quote author="Santosh Reddy" date="1361283872"]You already have things, but not in proper place. Simply do like this

            @ClipWidget(QWidget * parent = 0)
            : QWidget(parent)
            {
            m_pSecondaryListView = new QListView(this);
            QGridLayout *pgridlayout = new QGridLayout(this);

            m_pSecondaryListView->setEditTriggers(QListView::NoEditTriggers);
            pgridlayout->addWidget(m_pSecondaryListView);
            

            }@

            @ClipWidget * m_pClipWidget = new ClipWidget();
            m_pClipWidget->setFixedHeight(120);
            m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
            m_pClipWidget->show();@[/quote]

            --
            Thanks & Regards,
            Stoned Jesus

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Santosh Reddy
              wrote on last edited by
              #6

              Ok,
              @QWidget *pListWidget = new QWidget;
              QVBoxLayout *layout = new QVBoxLayout(pListWidget);

              ClipWidget * m_pClipWidget = new ClipWidget();
              m_pClipWidget->setFixedHeight(120);
              m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);

              layout->addWidget(m_pClipWidget);

              pListWidget->show();@

              SS

              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