winkle98
24th February 2012, 00:11
I just switched my app from using a QTableWidget to a QTableView and suddenly I cannot get word wrap to shut off.
My tableview has 5 columns 4 of which are hidden.
myTable = new QTableView( this );
myTable->setModel( myModel );
myTable->verticalHeader()->setVisible( false );
myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
myTable->setShowGrid( false );
myTable->setWordWrap( false );
myTable->horizontalHeader()->setStretchLastSection( false );
myTable->horizontalHeader()->resizeSections( QHeaderView::ResizeToContents );
//
// I have also tried, instead of calling resizeSections, the following
// mySequenceTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Interactive );
// mySequenceTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
myTable->horizontalHeader()->setSectionHidden( 2, true );
myTable->horizontalHeader()->setSectionHidden( 3, true );
myTable->horizontalHeader()->setSectionHidden( 4, true );
myTable->setSelectionBehavior( QAbstractItemView::SelectRows );
myTable->setSelectionMode( QAbstractItemView::SingleSelection );
myTable->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
myTable->setHorizontalScrollMode( QAbstractItemView::ScrollPerPixel );
The problem is that when an extremely long string is displayed in column 1 the text is wrapped. I'm need either a scroll bar (or if the scrollbar is set to off, the ellipses.) But I am always getting a wrapped string. The example above gives me a small column that I can drag to widden and when the column with becomes bigger than the QTableView then I do get the horizontal scrollbar, but I need the column to make itself bigger when the data appears in the model.
I have tried a few dozen iterations of this and am getting the same result. Can anyone offer a suggestion?
My tableview has 5 columns 4 of which are hidden.
myTable = new QTableView( this );
myTable->setModel( myModel );
myTable->verticalHeader()->setVisible( false );
myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
myTable->setShowGrid( false );
myTable->setWordWrap( false );
myTable->horizontalHeader()->setStretchLastSection( false );
myTable->horizontalHeader()->resizeSections( QHeaderView::ResizeToContents );
//
// I have also tried, instead of calling resizeSections, the following
// mySequenceTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Interactive );
// mySequenceTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
myTable->horizontalHeader()->setSectionHidden( 2, true );
myTable->horizontalHeader()->setSectionHidden( 3, true );
myTable->horizontalHeader()->setSectionHidden( 4, true );
myTable->setSelectionBehavior( QAbstractItemView::SelectRows );
myTable->setSelectionMode( QAbstractItemView::SingleSelection );
myTable->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
myTable->setHorizontalScrollMode( QAbstractItemView::ScrollPerPixel );
The problem is that when an extremely long string is displayed in column 1 the text is wrapped. I'm need either a scroll bar (or if the scrollbar is set to off, the ellipses.) But I am always getting a wrapped string. The example above gives me a small column that I can drag to widden and when the column with becomes bigger than the QTableView then I do get the horizontal scrollbar, but I need the column to make itself bigger when the data appears in the model.
I have tried a few dozen iterations of this and am getting the same result. Can anyone offer a suggestion?