mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-21 11:31:51 -05:00
Set foreign key item delegate references key values combo box size according to contents
This commit is contained in:
parent
7b4b407455
commit
86fb68f305
@ -1,7 +1,10 @@
|
||||
#include "ForeignKeyDelegate.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
|
||||
#include <QFontMetrics>
|
||||
#include <QSize>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include "CandidateKeyFilter.hpp"
|
||||
|
||||
ForeignKeyDelegate::ForeignKeyDelegate (QAbstractItemModel const * referenced_model
|
||||
@ -40,3 +43,20 @@ QWidget * ForeignKeyDelegate::createEditor (QWidget * parent
|
||||
editor->setSizeAdjustPolicy (QComboBox::AdjustToContents);
|
||||
return editor;
|
||||
}
|
||||
|
||||
QSize ForeignKeyDelegate::sizeHint (QStyleOptionViewItem const& option, QModelIndex const& index) const
|
||||
{
|
||||
auto size_hint = QStyledItemDelegate::sizeHint (option, index);
|
||||
QFontMetrics metrics {option.font};
|
||||
QStyleOptionComboBox combo_box_option;
|
||||
combo_box_option.rect = option.rect;
|
||||
combo_box_option.state = option.state | QStyle::State_Enabled;
|
||||
for (auto row = 0; row < candidate_key_filter_->rowCount (); ++row)
|
||||
{
|
||||
size_hint = size_hint.expandedTo (qApp->style ()->sizeFromContents (QStyle::CT_ComboBox
|
||||
, &combo_box_option
|
||||
, {metrics.width (candidate_key_filter_->data (candidate_key_filter_->index (row, 0)).toString ())
|
||||
, metrics.height ()}));
|
||||
}
|
||||
return size_hint;
|
||||
}
|
||||
|
@ -33,9 +33,10 @@ public:
|
||||
, int referencing_key_role = Qt::EditRole);
|
||||
~ForeignKeyDelegate ();
|
||||
|
||||
QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override;
|
||||
|
||||
private:
|
||||
QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override;
|
||||
QSize sizeHint (QStyleOptionViewItem const&, QModelIndex const&) const override;
|
||||
|
||||
QScopedPointer<CandidateKeyFilter> candidate_key_filter_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user