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. Change height of buttons inside QStringListModel
Forum Updated to NodeBB v4.3 + New Features

Change height of buttons inside QStringListModel

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.4k 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.
  • R Offline
    R Offline
    republicca
    wrote on last edited by
    #1

    Hi there!

    I have many buttons inside a List View, and in order to get a scroll bar when needed, I put all the buttons inside a QStringListModel like this:

    @
    for(int i=0; i<list.count(); i++)
    {
    button = new QPushButton;
    button->setText(list.at(i));
    index=model->index(i, 0, QModelIndex());
    listView->setIndexWidget(index, button);
    group->addButton(button);
    group->setId(button, i);
    }
    @

    The things is when I try to change the height of the button because I think its too small, the buttons overlap each other. I have no idea how I can resolve this, maybe changing the Model I insert my buttons in, or adding some kind of spacing between the buttons... I would appreciate any help.

    Btw I try to change the size of my buttons like this:

    @
    button->setMinimumHeight(23);
    button->setMaximumHeight(23);
    @

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Phani Madhavi
      wrote on last edited by
      #2

      try to apply stylesheet for buttons padding like that

      1 Reply Last reply
      0
      • R Offline
        R Offline
        republicca
        wrote on last edited by
        #3

        I tried this, but yet it doesnt work.

        @
        button->setStyleSheet("min-height: 23px; margin-top: 23px; margin-bottom: 10px;");
        @

        Still thank you for the answer!

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

          Hi,

          Styling the button won't help since it's not the button size that determines the cell height. Are you sure you need a QListView if you are creating a QPushButton for each entry in the model ?

          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
          • R Offline
            R Offline
            republicca
            wrote on last edited by
            #5

            Hi,
            I think I do. I need different buttonGroups inside the main window and the only thing I could think of was putting them inside a QListView, but I dont know if its correct.

            Are you guys sure that I use the correct model? QStringListModel is the only one I found, but maybe there is another that suits better.

            Anyways thenk you for the answer!

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

              Then first thing, why do you need a QStringListModel ?

              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
              • R Offline
                R Offline
                republicca
                wrote on last edited by
                #7

                Because I couldnt find any other way to automatically add a scrollbar when adding buttons to the QListView

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

                  That's not really related, the QStringListModel can be used to feed a QListView, but I don't see how it's related to generating your buttons e.g. where does your data come from to fill the QStringListModel ?

                  Anyway since it seems that you have to create a long widget full of buttons, you might be interested in QScrollArea

                  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
                  • R Offline
                    R Offline
                    republicca
                    wrote on last edited by
                    #9

                    I read a file from which I get some names that I add to the QStringListModel and those names inside the QStringListModel become the text inside the buttons, and the buttons are in the QListView.

                    I already tried doing that but got nowhere.

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

                      The simple way would be:
                      QWidget -> QVBoxLayout
                      fill the layout with buttons and set that widget in a QScrollArea

                      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