Skip to content

Commit 06a41ef

Browse files
committed
[welcome page] fix recent project list not resizing
1 parent e193c7c commit 06a41ef

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/app/qgswelcomepage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ QgsWelcomePage::QgsWelcomePage( QWidget* parent )
4242
recentProjctsContainer->layout()->addWidget( recentProjectsTitle );
4343

4444
QListView* recentProjectsListView = new QListView();
45+
recentProjectsListView->setResizeMode( QListView::Adjust );
46+
4547
mModel = new QgsWelcomePageItemsModel( recentProjectsListView );
4648
recentProjectsListView->setModel( mModel );
4749
recentProjectsListView->setItemDelegate( new QgsWelcomePageItemDelegate( recentProjectsListView ) );

src/app/qgswelcomepageitemsmodel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
3636
painter->save();
3737

3838
QTextDocument doc;
39+
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
40+
3941
QAbstractTextDocumentLayout::PaintContext ctx;
4042
QStyleOptionViewItemV4 optionV4 = option;
4143

@@ -71,9 +73,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
7173
int textSize = titleSize * 0.85;
7274

7375
doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
74-
doc.setTextWidth( 2800 );
76+
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
7577

76-
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
7778
if ( !icon.isNull() )
7879
{
7980
painter->drawPixmap( option.rect.left() + 10, option.rect.top() + 10, icon );
@@ -89,14 +90,13 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
8990
QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const
9091
{
9192
QTextDocument doc;
93+
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
9294

9395
int titleSize = QApplication::fontMetrics().height() * 1.1;
9496
int textSize = titleSize * 0.85;
9597

9698
doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
97-
doc.setTextWidth( 2800 );
98-
99-
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
99+
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
100100

101101
return QSize( option.rect.width(), qMax( doc.size().height() + 10, ( double )icon.height() ) + 20 );
102102
}

0 commit comments

Comments
 (0)