What is the best way to implement this with Qt

I am completely new to Qt, so I would be happy to receive a broad answer.

Here I made some model:

enter image description here

We have a table containing:

  • integer value with spinbon.
  • cell with three (not specially) grouped radio buttons
  • Editbox
  • A button that interacts with this particular edit field.

We also have 2 buttons for adding and removing items from the table.

I did some google searches and found out that this can be done through QTableView. Is there any way to put such complex structures in a cell? Should it be a separate class inherited from QTableView?

+5
source share
3 answers

If you have up to a hundred or maybe several hundred items in a table, use QTableWidget .

If you have too many elements (about a thousand), go to QTableView and study the model representation .

The reason I recommend QTableWidget is because you are new. All you have to do is create a widget and use setCellWidget() , and you're done.

If you have thousands of rows, you will have to draw widgets yourself using QStyledItemDelegate , which will draw widgets inside your QTableView . This is a very painful thing, but not around it. The reasons you can find here .

+2
source

I see at least three options for implementing this in Qt:

  • Use a QtableView or QTableWidget and paste some custom controls into it. See Comments made by others on your post.
  • Use a QGridLayout and populate it with row and column controls
  • Create your own QWidget for storing and managing line elements (format field, edit field, switch) using QHBoxLayout . You can create this in QtCreator, it can have its own .ui. This can simplify the handling of the interaction between each QWidget row (directly handled by your QWidget class). You can later put an instance for each row that you need in a QVBoxLayout .

Personnaly, I would use the latter option, but it may not work honestly if the controls on each line have different content / size (see comments), then the first options should be preferred.

+2
source

What you are looking for is the right layouts to place these components.

See Manage Layouts

Check out the examples .

You can achieve the desired layout using a combination of QGridLayout , QFormLayout and others that you think are appropriate according to your situation.

0
source

Source: https://habr.com/ru/post/1271426/


All Articles