Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Qt - Nested QTableView/QTableView displaying QStandardItemModel w/ column entries

$
0
0
Hi all, I’ve been working on this for awhile while learning Qt and I haven’t figured it out via the online documentation or forums, so I thought I’d ask. I’m basically trying to create a nested table. I have a .csv file being read into a QStandardItemModel and being displayed by a QTableView. The .csv file has a ‘|’ separated field (call it flags) which I want to expand vertically in the view. Condensened, the .csv looks something like this: NAME, FLAGS item1, a|b item2, c And I would like something like this displayed: NAME, FLAGS item1, a        b item2, c So, I create a QStandardItem and add the values ‘a’,‘b’,‘c’,‘d’ in a QList<QStandardItem*> using appendColumn, and put this returned item into the QStandardItemModel. (This is the code below). What happens, is the flags entries are blank. What I think is happening, is the value of QStandardItem in the Model is empty, the children of QStandardItem in the column I created are there, and QTableView doesn’t support showing the children. I spent a lot of time looking for the function that controls this behavior so I could override it for this particular column, but I can’t find it. I also thought about just putting a blank entry in all the other columns, but this doesn’t seem as clean as nesting the flags into a QStandardItem. I’m still learning Qt, so explanations of what Qt is doing are appreciated. Suggested solutions also appreciated. I’m not set on the QTableView and QStandardItemModel format, these just seemed most appropriate to me at the time. Thanks in advance! QStandardItem* ParseFlags(QString flagString) {     QStandardItem* ret = new QStandardItem();     QChar charIn; QString tempString;     QList<QStandardItem*> list;     for (int i=0; i<flagsString.length(); i++) {         charIn = flagsString[i]; // Get char         if (charIn == flagSeparator) { // If we hit the separator             list.append(new QStandardItem(tempString)); // add the string to the list             tempString.clear();             continue;         }         tempString.append(charIn);     }     // If we have a final string, add it to the list     if (!tempString.isEmpty()) {         list.append(new QStandardItem(tempString));     }       ret->appendColumn(list); // append the list we created to the return object     return(ret); }

Viewing all articles
Browse latest Browse all 18427

Trending Articles