Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.1
-
None
-
VS2008, Win-XP
Description
Hi,
My table should automatically word wrap and adapt line height according to contents.
It works basically, but when I reduce the width of a column then in the area where the word wrap should take place there is a mismatch between the sizehint and the drawing. The sizehint returns one line, but the drawing would already require two lines. Hence in a small range ellipses are seen. If I continue to reduce the column width then the line height is corrected.
This is very obvious with QItemDelegate, but for QStyledItemDelegate the mismatch also exists, though only for one pixel.
Example program header: wordwrap_tables.h
#ifndef WORDWRAP_TABLES_H #define WORDWRAP_TABLES_H #include <QtGui/QTableWidget> class MyTableWidget : public QTableWidget { Q_OBJECT public: MyTableWidget(); public slots: void slotHorizontalHeaderResized(int,int,int); }; #endif // WORDWRAP_TABLES_H
Example program cpp: main.cpp
#include <QtGui/QApplication> #include <QtGui/QHeaderView> #include <QtGui/QItemDelegate> #include "wordwrap_tables.h" MyTableWidget::MyTableWidget() { connect(horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(slotHorizontalHeaderResized(int,int,int))); verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ); } void MyTableWidget::slotHorizontalHeaderResized( int /*logicalIndex*/, int /*oldSize*/, int /*newSize*/ ) { verticalHeader()->resizeSections(QHeaderView::ResizeToContents); } int main(int argc, char *argv[]) { QApplication a(argc, argv); MyTableWidget* tableWidget = new MyTableWidget(); tableWidget->setItemDelegate( new QItemDelegate() ); tableWidget->setRowCount(3); tableWidget->setColumnCount(3); QTableWidgetItem *newItem = new QTableWidgetItem( "Somewhat long test string" ); tableWidget->setItem(0,0, newItem); tableWidget->show(); return a.exec(); }
I made a workaround by overwriting QItemDelegate::sizeHint(), but you might want to fix this too.
Best regards,
Joachim