Changeset View
Changeset View
Standalone View
Standalone View
Modules/samba/main.cpp
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 62 | { | |||
---|---|---|---|---|---|
66 | // TODO: replace i18n'd string to one without quick access marker | 66 | // TODO: replace i18n'd string to one without quick access marker | ||
67 | title->setText(text.remove("&")); | 67 | title->setText(text.remove("&")); | ||
68 | title->setLevel(2); | 68 | title->setLevel(2); | ||
69 | layout()->addWidget(title); | 69 | layout()->addWidget(title); | ||
70 | 70 | | |||
71 | auto view = new QTableView(this); | 71 | auto view = new QTableView(this); | ||
72 | layout()->addWidget(view); | 72 | layout()->addWidget(view); | ||
73 | view->setModel(model); | 73 | view->setModel(model); | ||
74 | | ||||
75 | // Stretching is a bit awkward because it allows resizing below the sizeHint of | ||||
76 | // the header, effectively cutting off the text. This is made worse by kcmshell | ||||
77 | // which rather unfortunately stacks scrollviews so size hinting is lost along | ||||
78 | // the way allowing the actual window to be (even by default) smaller than | ||||
79 | // what our preferred hint is. To mitigate this problem we manually make | ||||
80 | // the sizeHint's width the minimal size. This is kind of like QSizePolicy::Minimum. | ||||
81 | // https://bugs.kde.org/show_bug.cgi?id=419786 | ||||
82 | int maxSectionRequirement = 0; | ||||
83 | for (auto i = 0; i < view->model()->columnCount(); ++i) { | ||||
84 | const int hint = view->horizontalHeader()->sectionSizeHint(i); | ||||
85 | maxSectionRequirement = qMax<int>(maxSectionRequirement, hint); | ||||
86 | } | ||||
87 | view->horizontalHeader()->setMinimumSectionSize(maxSectionRequirement); | ||||
88 | // Combined with the minimum section size this makes sure the default size will | ||||
89 | // be minimal sufficient regardless of parent sizing policies and model content | ||||
90 | // i.e. an empty view will still have fine spacing for header text. | ||||
91 | view->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); | ||||
92 | | ||||
74 | view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | 93 | view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | ||
75 | view->horizontalHeader()->reset(); | 94 | view->horizontalHeader()->reset(); | ||
76 | view->horizontalHeader()->setVisible(true); | 95 | view->horizontalHeader()->setVisible(true); | ||
77 | view->verticalHeader()->setVisible(false); | 96 | view->verticalHeader()->setVisible(false); | ||
78 | 97 | | |||
79 | return view; | 98 | return view; | ||
80 | } | 99 | } | ||
81 | 100 | | |||
82 | #include "main.moc" | 101 | #include "main.moc" |