Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView vs subclassing QAbstractTableModel
QtWS25 Last Chance

QTableView vs subclassing QAbstractTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
modelviewqtableviewqabstracttablemqtreewidget
4 Posts 4 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Electric-Gecko
    wrote on 15 Oct 2017, 00:38 last edited by Electric-Gecko
    #1

    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?
    0_1508027222027_Screenshot_20171014_162914.png

    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?

    S 1 Reply Last reply 17 Oct 2017, 17:34
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Oct 2017, 21:12 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Electric-Gecko
        15 Oct 2017, 00:38

        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?
        0_1508027222027_Screenshot_20171014_162914.png

        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?

        S Offline
        S Offline
        samdol
        wrote on 17 Oct 2017, 17:34 last edited by samdol
        #3

        @Electric-Gecko
        QTreeWidget can show dropdown menu as you can see here

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 17 Oct 2017, 17:45 last edited by
          #4

          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

          use QStandardItem::setFlag

          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 QStandardItemModel::dataChanged signal

          There will be a button next to the table to add an additional note to the scale

          connect a slot that calls QStandardItemModel::insertRows to the QPushButton::clicked signal

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2

          1/4

          15 Oct 2017, 00:38

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved