Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Change height of buttons inside QStringListModel
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;
index=model->index(i, 0, QModelIndex());
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:
Phani Madhavi last edited by
try to apply stylesheet for buttons padding like that
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!
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 ?
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!
Then first thing, why do you need a QStringListModel ?
Because I couldnt find any other way to automatically add a scrollbar when adding buttons to the QListView
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
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.
The simple way would be:
QWidget -> QVBoxLayout
fill the layout with buttons and set that widget in a QScrollArea