Details
-
Bug
-
Resolution: Done
-
P4: Low
-
4.8.1
-
None
Description
Sometimes QHeaderView::ResizeToContents and resizeRowsToContents() lead to a slightly too small widget size in combination with word wrap:
It seems to appear more often when having a decoration data but also without it appears from time to time. It can be easily reproduced when resizing the window and watching the text wrap.
I created a minimal working example where the problem occurs:
main.cpp
#include <QtGui/QApplication> #include <QMainWindow> #include <QAbstractTableModel> #include <QList> #include <QString> #include <QResizeEvent> #include "ui_mainwindow.h" class MyModel : public QAbstractTableModel { Q_OBJECT QList<QString> items; public: MyModel(QWidget* parent = 0) : QAbstractTableModel(parent) { items.append("The less you know about computers the more you want Microsoft! -- Microsoft ad campaign, circa 1996"); } int rowCount(const QModelIndex& /*parent = QModelIndex()*/) const { return 1; } int columnCount(const QModelIndex& /*parent = QModelIndex()*/) const { return items.size(); } QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const { if (role == Qt::DisplayRole) return items[index.column()]; if (role == Qt::DecorationRole) return QIcon::fromTheme(QLatin1String("dialog-information")); else return QVariant(); } }; namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT Ui::MainWindow* ui; public: MainWindow(QWidget* parent = 0) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->tableView->setModel(new MyModel(this)); ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui->tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); ui->tableView->resizeRowsToContents(); ui->tableView->verticalHeader()->setVisible(false); } ~MainWindow() { delete ui; } }; #include "main.moc" // required due to single-file int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>264</width> <height>200</height> </rect> </property> <widget class="QWidget" name="centralWidget"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QTableView" name="tableView"/> </item> </layout> </widget> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
QtTest.pro
QT += core gui TARGET = QtTest TEMPLATE = app SOURCES += main.cpp FORMS += mainwindow.ui
The example is also attached as an archive.
Systems tested:
- Ubuntu 12.04.2 LTS, Qt 4.8.1-0ubuntu4.4
- Windows 7, Qt 4.8.0
Attachments
Issue Links
- relates to
-
QTBUG-62091 QHeaderView.paintSection text doesn't account for DecorationRole icon width
- Closed
For Gerrit Dashboard: QTBUG-30116 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
216660,5 | QCommonStylePrivate::viewItemSize: fix text height calculation | dev | qt/qtbase | Status: MERGED | +2 | 0 |
234399,3 | QCommonStylePrivate::viewItemSize: Fix text width bounds calculation | 5.11 | qt/qtbase | Status: MERGED | +2 | 0 |