Unsolved Determine Line Count for Certain Font w WordWrap at Runtime
-
I have a function called from QML, where QML passes a TableView index, column width and the string in question. I want to determine the line count so I can then dynamically determine the row height which the TableView rowDegate will use.
Here's some of the interaction from QML. When I click the row and I'm in the expanded state I want to combine text in columns 2 & 3 and then show that in column 3. I also need to dynamically determine the height of this combined text.
rowDelegate: Rectangle { id: tvRowDelegate height: 65 width: parent.width state: ((sqlELmodel.getExpanded(styleData.row)) ? "expanded" : "collapsed") states: [ State { name: "collapsed" PropertyChanges { target: tvRowDelegate; height: 65; } }, State { name: "expanded" PropertyChanges { target: tvRowDelegate; height: (sqlELmodel.getExpandedSL(styleData.row) === 0) ? 100 : (27*(sqlELmodel.getExpandedSL(styleData.row)) < 100) ? 100 : 27*(sqlELmodel.getExpandedSL(styleData.row)); } } ] MouseArea { anchors.fill: parent onClicked: { var cTxt cTxt = sqlELmodel.combineColumns(styleData.row, 2, 3) sqlELmodel.setExpandedSL(styleData.row, col3.width, cTxt) sqlELmodel.setExpanded(styleData.row, !sqlELmodel.getExpanded(styleData.row)) timerRow = styleData.row sqlELmodel.refresh() eventLogView.positionViewAtRow(timerRow, ListView.Beginning) } } }
This is a C++ object that runs all of my queries for the TableView QML object. I've added a QPlainTextEdit member (pte) and in the constructor I set some defaults so I don't have to do this for every call to setExpandedSL() which will be called as rows are rendered.
SqlQueryModel::SqlQueryModel(QObject* parent) : QSqlQueryModel(parent) { connect(&futureWatcher, SIGNAL(finished()), this, SLOT(valDone())); setValidate(false); // In constructor increase performance QFont viewFont("NotoSans", 19, QFont::Normal); viewFont.setPixelSize(19); pte.setFont(viewFont); pte.setAttribute(Qt::WA_DontShowOnScreen); pte.setWordWrapMode(QTextOption::WordWrap); }
Here's the real issue. The show() call works in Win10 just fine but fails on my embedded target and I have no idea why.
void SqlQueryModel::setExpandedSL(int idx, int w, QString str) { // Save the visual number of lines pte.setFixedWidth(w); pte.setPlainText(str); pte.show(); #ifdef VERBOSITY_HIGH qDebug() << "Exp line cnt: " << pte.document()->documentLayout()->documentSize().height(); #endif ExpandedStrLen[idx] = pte.document()->documentLayout()->documentSize().height(); }
I've tried alternates like pte.repaint(), pte.update(), pte.viewport()->... and pte.layout()->...
Any thoughts on what might cause the call to show() to hang or another way to force the layout to update so I can get the text line count for the font (constructor set) and word wrap mode I've set?
Thanks,
-Rich