I'm totally new to Qt, so I'd be glad to have a wide answer.
Here I drew up some model:
We have a kind of table that contains:
Also we have 2 buttons to add and remove items from the table.
I did some google search and found out that it can be done via QTableView. Is there any way to put such complex structures into a cell? Must it be a separate class inherited from QTableView?
If you're going to have up to a hundred or maybe a few hundreds of elements in the table, then use QTableWidget
.
If you're going to have too many elements (about thousands), then go for QTableView, and learn model-view programming.
The reason why I recommend QTableWidget
is because you're a beginner. All you have to do there is create a widget, and use setCellWidget()
and you're done.
If you have thousands of rows, then you're gonna have to draw the widgets yourself using QStyledItemDelegate
, which will paint the widgets inside your QTableView
. This is a very painful thing to do, but there's no way around it. The reasons you can find here.
I see at least three options to implement that in Qt:
QtableView
or QTableWidget
and insert some custom controls in it. See comments made be other persons to your postQGridLayout
and fill it with your controls by line and columnQWidget
to store and manage the line elements (the spinbox, edit field, radio button) using a QHBoxLayout
. You can design this in QtCreator, it can have it's own .ui. This could make it easy to handle the interaction between each QWidget
of a line (directly handled by your QWidget
class). Later, you can put an instance of it for every line you need in a QVBoxLayout
.Personnaly, I would go with the last option, but it may not work smartly if the controls of each line have different content/size (see comments), then first options should be prefered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With