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. [SOLVED] Display issue on QTableView
QtWS25 Last Chance

[SOLVED] Display issue on QTableView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.8k 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.
  • I Offline
    I Offline
    igleyy
    wrote on last edited by
    #1

    Greetings,

    Currently I'm working on specific application, overall subject is not important here. I want to create two views which use the same model. My model should contain information like this:

    • node name (QString as QVariant in Qt::DisplayRole),
    • map of property name and property value (map as QVariant in Qt::UserRole + 1).

    My QTreeView uses only node name (stored in DisplayRole of QStandardItem). Basically I want to select entry on my QTreeView and display every entry of selected element map in QTableView. How can I do this? Should I use somehow two models or stay with one? Maybe should I store my information somewhere else? All my current work is based on QStandardItemModel and QStandardItem. My QTableView have to display only selected item map entries, generally that's where I'm getting confused.

    In addition, I would like to have my table cells to be QLineEdits (or some derivative) - I would like to store last text cursor position (in order to paste something on that place). I should use custom delegate, am I correct?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      You probably want to subclass QAbstractItemModel similar to this "Example":http://harmattan-dev.nokia.com/docs/library/html/qt4/itemviews-editabletreemodel.html.

      In this case you can use only one model that gives all information to the treeview. You can control the amount of data within each item with the data() and the rowCount() methods. So there is no need to provide a map.

      I would suggest reading the descriptions in the example from above step by step and come back with questions.

      This, Jen, is the internet.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        igleyy
        wrote on last edited by
        #3

        I guess I understand concepts of subclassing QAbstractItemModel, but I did it other way. I've already prepared QStandardItemModel to store my specific information. My question is how to limit table view scope that it displays only my inner data from selected item in tree view. Any ideas?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          franku
          wrote on last edited by
          #4

          What do you mean with table view scope in respect to inner data? Do you want to select one item in a view, and the selected in a second?

          This, Jen, is the internet.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            igleyy
            wrote on last edited by
            #5

            Sorry, maybe I didn't explain it clearly enough. I'd like to have two views (which uses model). First view is tree view. I'd like to display there every item I have added to my model. That items would be identified by QString (QVariant in Qt::DisplayMode). Second view is table view. I'd like to display there every entry in QMap<QString, QString> (QVariant in Qt::UserRole + 1). And the most important thing - I'd like to display in table view properties (I mean QMap<QString, QString> I mentioned before) only from item that is selected in tree view. Literally I want to limit displaying scope of table view only to item that is selected in tree view.

            Hope it's clear right now :).

            @edit
            I managed to accomplish what I wanted. I simply create second model connected to table view. Then I connected tree view selection model signal (selectionChanged) to table view connected model custom slot (handleSelectionChange) which populates its model.

            1 Reply Last reply
            0

            • Login

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