From f399033b94f0f41dc3b07c5f3a69a87c7a7959bd Mon Sep 17 00:00:00 2001 From: David Solbach Date: Sun, 3 Oct 2010 12:26:25 +0200 Subject: [PATCH] recalculate and set widget size on data change --- src/main.cpp | 2 ++ src/mainwidget.cpp | 2 +- src/scoretable.cpp | 58 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3035873..ddedf42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,8 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); MainWidget mw; + mw.resize(400,200); + QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor(&mw); adaptor->setSettingsAvailable(true); QObject::connect(adaptor, SIGNAL(settingsRequested()), &mw, SLOT(showSettingsDialog())); diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 739e621..2c9422f 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -14,5 +14,5 @@ MainWidget::MainWidget(QWidget *parent) : this->setLayout(&layout); - this->setAutoFillBackground(false); + this->setAutoFillBackground(true); } diff --git a/src/scoretable.cpp b/src/scoretable.cpp index 2b5f1c3..78dd66d 100644 --- a/src/scoretable.cpp +++ b/src/scoretable.cpp @@ -12,42 +12,68 @@ ScoreTable::ScoreTable(QWidget *parent) : this->setModel(new MatchDayModel(this)); this->setSelectionMode(QAbstractItemView::NoSelection); - //this->verticalHeader()->hide(); - this->verticalHeader()->setStretchLastSection(false); + this->verticalHeader()->hide(); this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); this->verticalHeader()->setMinimumSectionSize(1); - //this->horizontalHeader()->hide(); + this->horizontalHeader()->hide(); this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); this->horizontalHeader()->setMinimumSectionSize(1); qDebug() << "Min VertHeaderSize: " << this->verticalHeader()->minimumSectionSize(); - this->viewport()->setAutoFillBackground(false); + this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + this->viewport()->setAutoFillBackground(true); this->setShowGrid(false); } QSize ScoreTable::sizeHint() const { - QSize i; - - i = (QSize(this->horizontalHeader()->width(), - this->verticalHeader()->height())); - - return i; + QSize s; + + for (int i = 0; i < horizontalHeader()->count(); i++) { + s.setWidth(s.width() + horizontalHeader()->sectionSize(i)); + } + // add missing few pixels (from borders mabye?) + // TODO: find better solution! + s.setWidth(s.width()); + for (int i = 0; i < verticalHeader()->count(); i++) { + s.setHeight(s.height() + verticalHeader()->sectionSize(i)); + } + // add missing few pixels (from borders mabye?) + // TODO: find better solution! + s.setHeight(s.height() + 3); + + return s; } void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { - QTableView::dataChanged(topLeft, bottomRight); - - qDebug() << "QTBV CR Size: " << this->childrenRect().size(); - qDebug() << "QTBVVP CR Size: " << this->childrenRect().size(); + QSize s; + // this will recalculate section sizes + QTableView::dataChanged(topLeft, bottomRight); - this->viewport()->resize(QSize(this->horizontalHeader()->width(), - this->verticalHeader()->height())); + for (int i = 0; i < horizontalHeader()->count(); i++) { + s.setWidth(s.width() + horizontalHeader()->sectionSize(i)); + } + // add missing few pixels (from borders mabye?) + // TODO: find better solution! + s.setWidth(s.width()); + for (int i = 0; i < verticalHeader()->count(); i++) { + s.setHeight(s.height() + verticalHeader()->sectionSize(i)); + } + // add missing few pixels (from borders mabye?) + // TODO: find better solution! + s.setHeight(s.height() + 3); + + this->resize(s); + this->parentWidget()->resize(s); + + qDebug() << s; updateGeometry(); -- 1.7.9.5