mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3449 Improve checkbox column size hint, alignment and "hit" rectanngle
This commit is contained in:
parent
979882da03
commit
bd79bd89c1
@ -59,6 +59,23 @@ PdmUiCheckBoxDelegate::~PdmUiCheckBoxDelegate()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QRect adjustedPaintRect(const QStyleOptionViewItem &option)
|
||||||
|
{
|
||||||
|
const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
|
||||||
|
|
||||||
|
QRect newRect = QStyle::alignedRect(option.direction,
|
||||||
|
Qt::AlignCenter,
|
||||||
|
QSize(option.decorationSize.width() + margin, option.rect.height()),
|
||||||
|
QRect(option.rect.x(),
|
||||||
|
option.rect.y(),
|
||||||
|
option.rect.width(),
|
||||||
|
option.rect.height()));
|
||||||
|
|
||||||
|
return newRect;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@ -66,16 +83,9 @@ PdmUiCheckBoxDelegate::~PdmUiCheckBoxDelegate()
|
|||||||
void PdmUiCheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void PdmUiCheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QStyleOptionViewItemV4 viewItemOption(option);
|
QStyleOptionViewItemV4 viewItemOption(option);
|
||||||
|
|
||||||
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
|
viewItemOption.rect = adjustedPaintRect(option);
|
||||||
QRect newRect = QStyle::alignedRect(option.direction,
|
|
||||||
Qt::AlignCenter,
|
|
||||||
QSize(option.decorationSize.width() + 5, option.rect.height()),
|
|
||||||
QRect(option.rect.x(),
|
|
||||||
option.rect.y(),
|
|
||||||
option.rect.width() - (2 * textMargin),
|
|
||||||
option.rect.height()));
|
|
||||||
viewItemOption.rect = newRect;
|
|
||||||
QStyledItemDelegate::paint(painter, viewItemOption, index);
|
QStyledItemDelegate::paint(painter, viewItemOption, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,15 +113,13 @@ bool PdmUiCheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model
|
|||||||
// make sure that we have the right event type
|
// make sure that we have the right event type
|
||||||
if (event->type() == QEvent::MouseButtonRelease)
|
if (event->type() == QEvent::MouseButtonRelease)
|
||||||
{
|
{
|
||||||
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
|
QRect paintRect = adjustedPaintRect(option);
|
||||||
QRect checkRect = QStyle::alignedRect(option.direction,
|
QRect checkRect = QStyle::alignedRect(option.direction,
|
||||||
Qt::AlignCenter,
|
Qt::AlignCenter,
|
||||||
option.decorationSize,
|
option.decorationSize,
|
||||||
QRect(option.rect.x() + (2 * textMargin),
|
paintRect);
|
||||||
option.rect.y(),
|
|
||||||
option.rect.width() - (2 * textMargin),
|
|
||||||
option.rect.height()));
|
|
||||||
|
|
||||||
if (!checkRect.contains(static_cast<QMouseEvent*>(event)->pos()))
|
if (!checkRect.contains(static_cast<QMouseEvent*>(event)->pos()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -129,6 +137,13 @@ bool PdmUiCheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model
|
|||||||
return model->setData(index, state, Qt::CheckStateRole);
|
return model->setData(index, state, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QSize PdmUiCheckBoxDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return QSize(option.decorationSize.width(), option.decorationSize.height());
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace caf
|
} // end namespace caf
|
||||||
|
|
||||||
|
@ -57,6 +57,9 @@ public:
|
|||||||
|
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
|
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||||
|
|
||||||
|
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user