Its not as per my requirement. I am using 'setSectionResizeMode'. Does it affects word wrap??
Yes if you use QHeaderView::Stretch, as QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically.
This works perfectly
#include <QtGui>
#include <QtWidgets>
#include <QApplication>
int main(int argc, char **argv)
{
int rows = 10;
model->setColumnCount(1);
QString readString
= "Moscow: Oleg Topalov could be credited with engineering one of the most daring prison breaks ever. The 33-year-old escaped from one of the highest security Russian prison using kitchen utensils.";
for (int r = 0; r < rows; r++) {
for (int column = 0; column < 1; column++) {
model->setData(mindex,readString);
}
}
tableView->setModel(model);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < 1; c++) {
vhdr
->setSectionResizeMode
(r,
QHeaderView::ResizeToContents);
}
}
tableView->setWordWrap(true);
// tableView->setTextElideMode(Qt::ElideLeft);
// tableView->resizeColumnsToContents();
// tableView->resizeRowsToContents();
tableView->show();
return app.exec();
}
#include <QtGui>
#include <QtWidgets>
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QTableView * tableView = new QTableView;
int rows = 10;
QStandardItemModel *model= new QStandardItemModel(rows,1);
model->setColumnCount(1);
QString readString = "Moscow: Oleg Topalov could be credited with engineering one of the most daring prison breaks ever. The 33-year-old escaped from one of the highest security Russian prison using kitchen utensils.";
for (int r = 0; r < rows; r++) {
for (int column = 0; column < 1; column++) {
QModelIndex mindex = model->index(r, column);
model->setData(mindex,readString);
}
}
tableView->setModel(model);
QHeaderView* hhdr = tableView->horizontalHeader();
QHeaderView* vhdr = tableView->verticalHeader();
for (int r = 0; r < rows; r++) {
for (int c = 0; c < 1; c++) {
vhdr->setSectionResizeMode(r, QHeaderView::ResizeToContents);
hhdr->setSectionResizeMode(c, QHeaderView::Stretch);
}
}
tableView->setWordWrap(true);
// tableView->setTextElideMode(Qt::ElideLeft);
// tableView->resizeColumnsToContents();
// tableView->resizeRowsToContents();
tableView->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks