-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolumnalignedlayout.cpp
More file actions
46 lines (35 loc) · 1.11 KB
/
columnalignedlayout.cpp
File metadata and controls
46 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "columnalignedlayout.h"
#include <QHeaderView>
ColumnAlignedLayout::ColumnAlignedLayout()
: QHBoxLayout()
{
}
ColumnAlignedLayout::ColumnAlignedLayout(QWidget *parent)
: QHBoxLayout(parent)
{
}
void ColumnAlignedLayout::setGeometry(const QRect &r)
{
QHBoxLayout::setGeometry(r);
Q_ASSERT_X(headerView, "layout", "no table columns to track");
if (!headerView) {
return;
}
Q_ASSERT_X(headerView->count() == count(), "layout", "there must be as many items in the layout as there are columns in the table");
if (headerView->count() != count()) {
return;
}
Q_ASSERT(parentWidget());
int widgetX = parentWidget()->mapToGlobal(QPoint(0, 0)).x();
int headerX = headerView->mapToGlobal(QPoint(0, 0)).x();
int delta = headerX - widgetX;
for (int ii = 0; ii < headerView->count(); ++ii) {
int pos = headerView->sectionViewportPosition(ii);
int size = headerView->sectionSize(ii);
auto item = itemAt(ii);
auto r = item->geometry();
r.setLeft(pos + delta);
r.setWidth(size);
item->setGeometry(r);
}
}