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. QListView in QSplitter not using entire available size.
Forum Updated to NodeBB v4.3 + New Features

QListView in QSplitter not using entire available size.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 1.6k 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.
  • Y Offline
    Y Offline
    YokeM
    wrote on last edited by
    #1

    Hello,

    I have a QTableView, QLineEdit and QListView in a QDockWidget and use a QSplitter for the layout. I get a lot of free space which I would like the QListView to have. I have used multiple functions found in QtDocs, but none of them let me change the size of the QListView. If I remove the QListView from the QSplitter, the space is nicely distributed between QTableView and QLineEdit, so I'm assuming I'm doing something wrong with the QListView. Picture 1 is the current state and picture 2 is what I want to have.

    0_1535105744654_Tool.png
    0_1535106203124_Tool_evenly.png

    jsulmJ 1 Reply Last reply
    0
    • Y YokeM

      Hello,

      I have a QTableView, QLineEdit and QListView in a QDockWidget and use a QSplitter for the layout. I get a lot of free space which I would like the QListView to have. I have used multiple functions found in QtDocs, but none of them let me change the size of the QListView. If I remove the QListView from the QSplitter, the space is nicely distributed between QTableView and QLineEdit, so I'm assuming I'm doing something wrong with the QListView. Picture 1 is the current state and picture 2 is what I want to have.

      0_1535105744654_Tool.png
      0_1535106203124_Tool_evenly.png

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @YokeM Actually you just need to layout all this in the parent widget.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Y 1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        One possibility is that you have setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        Y 1 Reply Last reply
        0
        • jsulmJ jsulm

          @YokeM Actually you just need to layout all this in the parent widget.

          Y Offline
          Y Offline
          YokeM
          wrote on last edited by
          #4

          @jsulm I can set a fixed size, but if I change the size at runtime, the QListView will not be resized obviously, as it has a fixed size.

          1 Reply Last reply
          0
          • VRoninV VRonin

            One possibility is that you have setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);

            Y Offline
            Y Offline
            YokeM
            wrote on last edited by
            #5

            @VRonin Thanks, I can do that, but I want the QListView have to fill the entire space that is left. If I change the policy to QAbstractScrollArea::AdjustToContents, the QListView will be adjusted to the needs of the contents. I.e.: if the contents only need a small amount of space, then the QListView also be very small.

            VRoninV 1 Reply Last reply
            0
            • Y YokeM

              @VRonin Thanks, I can do that, but I want the QListView have to fill the entire space that is left. If I change the policy to QAbstractScrollArea::AdjustToContents, the QListView will be adjusted to the needs of the contents. I.e.: if the contents only need a small amount of space, then the QListView also be very small.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @YokeM Yes, sorry, I was actually highlighting it as a possible cause of the problem. I wasn't clear.

              Can you show the code you use to add the widgets to the splitter?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              Y 1 Reply Last reply
              0
              • VRoninV VRonin

                @YokeM Yes, sorry, I was actually highlighting it as a possible cause of the problem. I wasn't clear.

                Can you show the code you use to add the widgets to the splitter?

                Y Offline
                Y Offline
                YokeM
                wrote on last edited by YokeM
                #7

                @VRonin Sure:

                ListView:

                .h:

                class...
                {
                ...
                        QListView  *listView;
                }
                

                .cpp:

                void func ...
                {
                ...
                	listView = new QListView(this);
                	listView->setModel(listModel);
                	listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
                }
                

                Splitter:

                .h:

                class...
                {
                ...
                         QSplitter *componentSplitter;
                }
                

                .cpp:

                void func ...
                {
                ...
                	componentSplitter = new QSplitter(this);
                	componentSplitter->setOrientation(Qt::Vertical);
                	componentSplitter->setChildrenCollapsible(false);
                        componentSplitter->addWidget(descriptionComponent);
                }
                
                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  The code you posted is missing the key link. how does listView end up in componentSplitter?

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  Y 1 Reply Last reply
                  0
                  • VRoninV VRonin

                    The code you posted is missing the key link. how does listView end up in componentSplitter?

                    Y Offline
                    Y Offline
                    YokeM
                    wrote on last edited by
                    #9

                    @VRonin My bad:

                    using: void QSplitter::addWidget(QWidget *widget)

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      The problem is that with your code, you have one class with a QListView and another one with a QSplitter, how are they connected to each other ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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