Skip to content

Commit

Permalink
Merge pull request #1597 from timblechmann/topic/ide-iconwidth-fix
Browse files Browse the repository at this point in the history
scide: preferences dialog - fix width of icon list widget
  • Loading branch information
scztt committed Jul 7, 2015
2 parents e248067 + 5a3a6cd commit c9b2105
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
13 changes: 11 additions & 2 deletions editors/sc-ide/forms/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@
<item>
<widget class="ScIDE::IconListWidget" name="configPageList">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -42,6 +48,9 @@
<property name="isWrapping" stdset="0">
<bool>false</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="viewMode">
<enum>QListView::ListMode</enum>
</property>
Expand Down
3 changes: 3 additions & 0 deletions editors/sc-ide/widgets/settings/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Dialog::Dialog( Manager *settings, QWidget * parent ):
connect(ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(reset()));


ui->configPageList->setMinimumWidth( ui->configPageList->sizeHintForColumn(0) );

reset();
}

Expand Down
15 changes: 13 additions & 2 deletions editors/sc-ide/widgets/util/icon_list_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ class IconListWidget : public QListWidget
ItemDelegate(QObject *parent) : QStyledItemDelegate(parent) {}

virtual QSize sizeHint
( const QStyleOptionViewItem & opt, const QModelIndex & index ) const
( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
return QStyledItemDelegate::sizeHint(opt, index) + QSize(0, 10);
QIcon icon(index.data(Qt::DecorationRole).value<QIcon>());
QSize iconSize = icon.actualSize(option.decorationSize);

QString text = index.data(Qt::DisplayRole).toString();
QFontMetrics fm( option.font );

int fontWidth = fm.width( text );

QSize requiredSize ( qMax( fontWidth, iconSize.width() ),
fm.height() + iconSize.height() );

return requiredSize + QSize(5, 5);
}

virtual void paint
Expand Down

0 comments on commit c9b2105

Please sign in to comment.