QTableView vs subclassing QAbstractTableModel
Electric-Gecko last edited by Electric-Gecko
I don't know if I should use QTableView or if I should subclass QAbstractTableModel for my application;or even QTreeView. It would be nice if someone went over the reasons why someone should choose one over the other.
All my Qt development experience comes from my (so far unmerged) contributions to QSynth. QSynth uses a few QTreeWidgets which all look something like the one in this image below. I wonder if it's use of QTreeWidget is unconventional, as none of the QTreeWidgets in QSynth have the drop-down lists that I see on images online. Is QTableView typically used for this purpose?
But anyway, I know that I can't use either QTreeWidget or QTableWidget for what I want to do now. I want to make a musical scale editor. It will have a table (looking similar to the one the image), but only some columns will be editable. The table will be a list of notes in the scale. Entering a value in the cents column (a logarithmic measure of frequency) will change the value in the hertz column, and vice versa. There will be a button next to the table to add an additional note to the scale.
So should I use QTableView, make a subclass of QAbstractTableModel, or something else?
Hi and welcome to devnet,
QTableView needs a model, so you have to make your own model anyway. From your description, it looks like a good option.
samdol last edited by samdol
QSynth simply may not created child items. So if you don't need dropdown menu, QTableWidget would be a good choice for simplicity.
You can edit or add new row on table in both QTableWidget or QTableView(by changing QAbstractTable Model). Model-View approach has some advantage compared to QTableView or QTreeView for it uses the same model to show on QTreeView and QTableView.
You can use either QTreeWidget, QTableWidget, QTreeView+QStandardItemModel, QTableView+QStandardItemModel, QTreeView+QAbstactTableModel subclass, QTableView+QAbstactTableModel subclass for what you are trying to do.
I would go with a QT*View+QStandardItemModel (tree or table doesn't matter).
The functionalities you describe are:
only some columns will be editable
Entering a value in the cents column (a logarithmic measure of frequency) will change the value in the hertz column, and vice versa
connect a slot to
There will be a button next to the table to add an additional note to the scale
connect a slot that calls