Cupidvogel
23rd May 2015, 14:32
I have a QPuhButton of fixed width. I want that whenever the text inside reaches the end with more text to follow, it should automatically add ellipsis, the way we can do in HTML content in web pages. I tried this:
tableWidget = new QTableWidget(1,2,this);
tableWidget->setGeometry(15,169,251,232);
tableWidget->setColumnWidth(0,198);
tableWidget->setColumnWidth(1,54);
QPushButton *textSnippet = new QPushButton();
textSnippet->setStyleSheet("text-align: left; border: none; padding-left: 10px;");
textSnippet->setCursor(Qt::PointingHandCursor);
QString qText = "Some text";
QFontMetrics metrics(textSnippet->font());
QString elidedText = metrics.elidedText(qText, Qt::ElideRight, textSnippet->width()-5);
textSnippet->setText(elidedText);
tableWidget->setCellWidget(0,1, textSnippet);
This does not work at all, the text continues until the very end and there is no ellipsis. Of course, I tried checking for a fixed number of characters (25), so that if the length of the text is beyond that, slice the first 25 characters and append an ellipsis and show it, but this results in a very non-uniform set of rows with ellipsis appearing at various positions in different rows.
How do I do it?
tableWidget = new QTableWidget(1,2,this);
tableWidget->setGeometry(15,169,251,232);
tableWidget->setColumnWidth(0,198);
tableWidget->setColumnWidth(1,54);
QPushButton *textSnippet = new QPushButton();
textSnippet->setStyleSheet("text-align: left; border: none; padding-left: 10px;");
textSnippet->setCursor(Qt::PointingHandCursor);
QString qText = "Some text";
QFontMetrics metrics(textSnippet->font());
QString elidedText = metrics.elidedText(qText, Qt::ElideRight, textSnippet->width()-5);
textSnippet->setText(elidedText);
tableWidget->setCellWidget(0,1, textSnippet);
This does not work at all, the text continues until the very end and there is no ellipsis. Of course, I tried checking for a fixed number of characters (25), so that if the length of the text is beyond that, slice the first 25 characters and append an ellipsis and show it, but this results in a very non-uniform set of rows with ellipsis appearing at various positions in different rows.
How do I do it?