Shrink long word wrap text in data model.
This commit is contained in:
@@ -15,7 +15,15 @@ protected:
|
|||||||
QVariant data(const QModelIndex& index, int role) const override {
|
QVariant data(const QModelIndex& index, int role) const override {
|
||||||
if (index.column() >0 && role == Qt::TextAlignmentRole) {
|
if (index.column() >0 && role == Qt::TextAlignmentRole) {
|
||||||
return Qt::AlignCenter;
|
return Qt::AlignCenter;
|
||||||
} else {
|
}
|
||||||
|
if (index.column() >0 && role == Qt::DisplayRole){
|
||||||
|
auto val = QSqlTableModel::data(index,role).toString();
|
||||||
|
QStringList list = val.split("\n");
|
||||||
|
if (list.size()>1)
|
||||||
|
return QString("%1...").arg(list[0].left(list[0].length()<20?list[0].length():20));
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return QSqlTableModel::data(index,role);
|
return QSqlTableModel::data(index,role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user