Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to implement this using Qt

Tags:

I'm totally new to Qt, so I'd be glad to have a wide answer.

Here I drew up some model:

enter image description here

We have a kind of table that contains:

  • an integer value with a spinbox.
  • a cell with three(not specifically) grouped radio buttons
  • Editbox
  • A button that interacts with this particular editbox.

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?

like image 551
Alignant Avatar asked Sep 01 '17 11:09

Alignant


2 Answers

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.

like image 126
The Quantum Physicist Avatar answered Sep 21 '22 14:09

The Quantum Physicist


I see at least three options to implement that in Qt:

  • Use a QtableView or QTableWidget and insert some custom controls in it. See comments made be other persons to your post
  • Use a QGridLayout and fill it with your controls by line and column
  • Make your own QWidget 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.

like image 22
jpo38 Avatar answered Sep 24 '22 14:09

jpo38