mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Improve shortcuts dialog interactive resize
This commit is contained in:
parent
b2ffa02b75
commit
aedfa16e42
2 changed files with 24 additions and 11 deletions
|
@ -47,40 +47,48 @@ float lcParseValueLocalized(const QString& Value)
|
|||
|
||||
// Resize all columns to content except for one stretching column. (taken from QT creator)
|
||||
lcQTreeWidgetColumnStretcher::lcQTreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
|
||||
: QObject(treeWidget->header()), m_columnToStretch(columnToStretch)
|
||||
: QObject(treeWidget->header()), m_columnToStretch(columnToStretch), m_stretchWidth(0)
|
||||
{
|
||||
parent()->installEventFilter(this);
|
||||
connect(treeWidget->header(), SIGNAL(sectionResized(int, int, int)), SLOT(sectionResized(int, int, int)));
|
||||
QHideEvent fake;
|
||||
lcQTreeWidgetColumnStretcher::eventFilter(parent(), &fake);
|
||||
}
|
||||
|
||||
void lcQTreeWidgetColumnStretcher::sectionResized(int LogicalIndex, int OldSize, int NewSize)
|
||||
{
|
||||
Q_UNUSED(OldSize)
|
||||
|
||||
if (LogicalIndex == m_columnToStretch)
|
||||
m_stretchWidth = NewSize;
|
||||
}
|
||||
|
||||
bool lcQTreeWidgetColumnStretcher::eventFilter(QObject* Object, QEvent* Event)
|
||||
{
|
||||
if (Object == parent())
|
||||
{
|
||||
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
|
||||
|
||||
if (Event->type() == QEvent::Show)
|
||||
{
|
||||
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
|
||||
|
||||
for (int i = 0; i < HeaderView->count(); ++i)
|
||||
HeaderView->setSectionResizeMode(i, QHeaderView::Interactive);
|
||||
|
||||
m_stretchWidth = HeaderView->sectionSize(m_columnToStretch);
|
||||
|
||||
}
|
||||
else if (Event->type() == QEvent::Hide)
|
||||
{
|
||||
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
|
||||
|
||||
for (int i = 0; i < HeaderView->count(); ++i)
|
||||
HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents);
|
||||
}
|
||||
else if (Event->type() == QEvent::Resize)
|
||||
{
|
||||
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(Object);
|
||||
if (HeaderView->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive) {
|
||||
|
||||
if (HeaderView->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive)
|
||||
{
|
||||
const QResizeEvent* ResizeEvent = reinterpret_cast<QResizeEvent*>(Event);
|
||||
const int Diff = ResizeEvent->size().width() - ResizeEvent->oldSize().width() ;
|
||||
HeaderView->resizeSection(m_columnToStretch, qMax(32, HeaderView->sectionSize(1) + Diff));
|
||||
const int StretchWidth = HeaderView->isVisible() ? m_stretchWidth : 32;
|
||||
|
||||
HeaderView->resizeSection(m_columnToStretch, StretchWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,12 @@ public:
|
|||
|
||||
bool eventFilter(QObject* Object, QEvent* Event) override;
|
||||
|
||||
private slots:
|
||||
void sectionResized(int LogicalIndex, int OldSize, int NewSize);
|
||||
|
||||
private:
|
||||
const int m_columnToStretch;
|
||||
int m_stretchWidth;
|
||||
};
|
||||
|
||||
class lcSmallLineEdit : public QLineEdit
|
||||
|
|
Loading…
Add table
Reference in a new issue