Your example does work for me. However, the difference is that I need for column 2 to show the elides and column 4 to be hidden. What I'm doing is more:
#include <QtGui>
int main(int argc, char *argv[])
{
model.
setStringList(QStringList() <<
"Very very long line of text" << "Very very long line of text"
<< "short text"
<< "short text");
view.setModel(&model);
view.
horizontalHeader()->setResizeMode
( 0,
QHeaderView::Interactive);
view.
horizontalHeader()->setResizeMode
( 1,
QHeaderView::Stretch );
view.setSectionHidden( 2, true );
view.setSectionHidden( 3, true );
view.show();
return a.exec();
}
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStringListModel model;
model.setStringList(QStringList() << "Very very long line of text"
<< "Very very long line of text"
<< "short text"
<< "short text");
QTableView view;
view.setModel(&model);
view.horizontalHeader()->setResizeMode( 0, QHeaderView::Interactive);
view.horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
view.setSectionHidden( 2, true );
view.setSectionHidden( 3, true );
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
For me this approach (I'm using c++ not python) the table view INSISTS on wrapping the contents of the column. If I don't stretch the second column, the text is still wrapped, but the user can resize the column. However, it has a huge block of dead space. ( there is a reason that those columns are hidden. )
It's looking like my only option is to handle the elide myself, in the column's delegate.
Bookmarks