Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtoolbarlayout.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include <qapplication.h>
6#include <qaction.h>
7#include <qwidgetaction.h>
8#include <qtoolbar.h>
9#include <qstyleoption.h>
10#if QT_CONFIG(toolbutton)
11#include <qtoolbutton.h>
12#endif
13#include <qmenu.h>
14#include <qdebug.h>
15#include <qmath.h>
16#ifdef Q_OS_MACOS
17#include <qpa/qplatformnativeinterface.h>
18#endif
19
21#if QT_CONFIG(toolbutton)
22#include "qtoolbarextension_p.h"
23#endif
26
28
29// qmainwindow.cpp
30extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
31
32/******************************************************************************
33** QToolBarItem
34*/
35
36QToolBarItem::QToolBarItem(QWidget *widget)
37 : QWidgetItem(widget), action(nullptr), customWidget(false)
38{
39}
40
41bool QToolBarItem::isEmpty() const
42{
43 return action == nullptr || !action->isVisible();
44}
45
46/******************************************************************************
47** QToolBarLayout
48*/
49
50QToolBarLayout::QToolBarLayout(QWidget *parent)
51 : QLayout(parent), expanded(false), animating(false), dirty(true),
52 expanding(false), empty(true), expandFlag(false), popupMenu(nullptr)
53{
54 QToolBar *tb = qobject_cast<QToolBar*>(parent);
55 if (!tb)
56 return;
57
58 extension = new QToolBarExtension(tb);
59 extension->setFocusPolicy(Qt::NoFocus);
60 extension->hide();
61 QObject::connect(tb, SIGNAL(orientationChanged(Qt::Orientation)),
62 extension, SLOT(setOrientation(Qt::Orientation)));
63
64 setUsePopupMenu(qobject_cast<QMainWindow*>(tb->parentWidget()) == 0);
65}
66
67QToolBarLayout::~QToolBarLayout()
68{
69 while (!items.isEmpty()) {
70 QToolBarItem *item = items.takeFirst();
71 if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action)) {
72 if (item->customWidget)
73 widgetAction->releaseWidget(item->widget());
74 }
75 delete item;
76 }
77}
78
79void QToolBarLayout::updateMarginAndSpacing()
80{
81 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
82 if (!tb)
83 return;
84 QStyle *style = tb->style();
85 QStyleOptionToolBar opt;
86 tb->initStyleOption(&opt);
87 const int margin = style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb)
88 + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb);
89 setContentsMargins(margin, margin, margin, margin);
90 setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, tb));
91}
92
93bool QToolBarLayout::hasExpandFlag() const
94{
95 return expandFlag;
96}
97
98void QToolBarLayout::setUsePopupMenu(bool set)
99{
100 if (!dirty && ((popupMenu == nullptr) == set))
101 invalidate();
102 if (!set) {
103 QObject::connect(extension, SIGNAL(clicked(bool)),
104 this, SLOT(setExpanded(bool)), Qt::UniqueConnection);
105 extension->setPopupMode(QToolButton::DelayedPopup);
106 extension->setMenu(nullptr);
107 delete popupMenu;
108 popupMenu = nullptr;
109 } else {
110 QObject::disconnect(extension, SIGNAL(clicked(bool)),
111 this, SLOT(setExpanded(bool)));
112 extension->setPopupMode(QToolButton::InstantPopup);
113 if (!popupMenu) {
114 popupMenu = new QMenu(extension);
115 }
116 extension->setMenu(popupMenu);
117 }
118}
119
120void QToolBarLayout::checkUsePopupMenu()
121{
122 QToolBar *tb = static_cast<QToolBar *>(parent());
123 QMainWindow *mw = qobject_cast<QMainWindow *>(tb->parent());
124 Qt::Orientation o = tb->orientation();
125 setUsePopupMenu(!mw || tb->isFloating() || perp(o, expandedSize(mw->size())) >= perp(o, mw->size()));
126}
127
128void QToolBarLayout::addItem(QLayoutItem*)
129{
130 qWarning("QToolBarLayout::addItem(): please use addAction() instead");
131 return;
132}
133
134QLayoutItem *QToolBarLayout::itemAt(int index) const
135{
136 if (index < 0 || index >= items.size())
137 return nullptr;
138 return items.at(index);
139}
140
141QLayoutItem *QToolBarLayout::takeAt(int index)
142{
143 if (index < 0 || index >= items.size())
144 return nullptr;
145 QToolBarItem *item = items.takeAt(index);
146
147 if (popupMenu)
148 popupMenu->removeAction(item->action);
149
150 QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action);
151 if (widgetAction != nullptr && item->customWidget) {
152 widgetAction->releaseWidget(item->widget());
153 } else {
154 // destroy the QToolButton/QToolBarSeparator
155 item->widget()->hide();
156 item->widget()->deleteLater();
157 }
158
159 invalidate();
160 return item;
161}
162
163void QToolBarLayout::insertAction(int index, QAction *action)
164{
165 index = qMax(0, index);
166 index = qMin(items.size(), index);
167
168 QToolBarItem *item = createItem(action);
169 if (item) {
170 items.insert(index, item);
171 invalidate();
172 }
173}
174
175int QToolBarLayout::indexOf(const QAction *action) const
176{
177 for (int i = 0; i < items.size(); ++i) {
178 if (items.at(i)->action == action)
179 return i;
180 }
181 return -1;
182}
183
184int QToolBarLayout::count() const
185{
186 return items.size();
187}
188
189bool QToolBarLayout::isEmpty() const
190{
191 if (dirty)
192 updateGeomArray();
193 return empty;
194}
195
196void QToolBarLayout::invalidate()
197{
198 dirty = true;
199 QLayout::invalidate();
200}
201
202Qt::Orientations QToolBarLayout::expandingDirections() const
203{
204 if (dirty)
205 updateGeomArray();
206 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
207 if (!tb)
208 return {};
209 Qt::Orientation o = tb->orientation();
210 return expanding ? Qt::Orientations(o) : Qt::Orientations{};
211}
212
213bool QToolBarLayout::movable() const
214{
215 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
216 if (!tb)
217 return false;
218 QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget());
219 return tb->isMovable() && win != nullptr;
220}
221
222void QToolBarLayout::updateGeomArray() const
223{
224 if (!dirty)
225 return;
226
227 QToolBarLayout *that = const_cast<QToolBarLayout*>(this);
228
229 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
230 if (!tb)
231 return;
232 QStyle *style = tb->style();
233 QStyleOptionToolBar opt;
234 tb->initStyleOption(&opt);
235 const int handleExtent = movable()
236 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
237 const QMargins margins = contentsMargins();
238 const int spacing = this->spacing();
239 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
240 Qt::Orientation o = tb->orientation();
241
242 that->minSize = QSize(0, 0);
243 that->hint = QSize(0, 0);
244 rperp(o, that->minSize) = style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb);
245 rperp(o, that->hint) = style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb);
246
247 that->expanding = false;
248 that->empty = false;
249
250 QList<QLayoutStruct> a(items.size() + 1); // + 1 for the stretch
251
252 int count = 0;
253 for (int i = 0; i < items.size(); ++i) {
254 QToolBarItem *item = items.at(i);
255
256 QSize max = item->maximumSize();
257 QSize min = item->minimumSize();
258 QSize hint = item->sizeHint();
259 Qt::Orientations exp = item->expandingDirections();
260 bool empty = item->isEmpty();
261
262 that->expanding = expanding || exp & o;
263
264
265 if (item->widget()) {
266 if ((item->widget()->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag)) {
267 that->expandFlag = true;
268 }
269 }
270
271 if (!empty) {
272 if (count == 0) // the minimum size only displays one widget
273 rpick(o, that->minSize) += pick(o, min);
274 int s = perp(o, minSize);
275 rperp(o, that->minSize) = qMax(s, perp(o, min));
276
277 //we only add spacing before item (ie never before the first one)
278 rpick(o, that->hint) += (count == 0 ? 0 : spacing) + pick(o, hint);
279 s = perp(o, that->hint);
280 rperp(o, that->hint) = qMax(s, perp(o, hint));
281 ++count;
282 }
283
284 a[i].sizeHint = pick(o, hint);
285 a[i].maximumSize = pick(o, max);
286 a[i].minimumSize = pick(o, min);
287 a[i].expansive = exp & o;
288 if (o == Qt::Horizontal)
289 a[i].stretch = item->widget()->sizePolicy().horizontalStretch();
290 else
291 a[i].stretch = item->widget()->sizePolicy().verticalStretch();
292 a[i].empty = empty;
293 }
294
295 that->geomArray = a;
296 that->empty = count == 0;
297
298 rpick(o, that->minSize) += handleExtent;
299 that->minSize += QSize(pick(Qt::Horizontal, margins), pick(Qt::Vertical, margins));
300 if (items.size() > 1)
301 rpick(o, that->minSize) += spacing + extensionExtent;
302
303 rpick(o, that->hint) += handleExtent;
304 that->hint += QSize(pick(Qt::Horizontal, margins), pick(Qt::Vertical, margins));
305 that->dirty = false;
306}
307
309{
310 QWidgetAction *a = qobject_cast<QWidgetAction*>(item->action);
311 return a != nullptr && a->defaultWidget() == item->widget();
312}
313
314void QToolBarLayout::updateMacBorderMetrics()
315{
316#ifdef Q_OS_MACOS
317 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
318 if (!tb)
319 return;
320
321 QRect rect = geometry();
322
323 QMainWindow *mainWindow = qobject_cast<QMainWindow*>(tb->parentWidget());
324 if (!mainWindow || !mainWindow->isWindow() || !mainWindow->unifiedTitleAndToolBarOnMac())
325 return;
326
327 extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
328 auto *mainWindowLayout = qt_mainwindow_layout(mainWindow);
329
330 QPoint upper = tb->mapToParent(rect.topLeft());
331 QPoint lower = tb->mapToParent(rect.bottomLeft() + QPoint(0, 1));
332
333 if (mainWindow->toolBarArea(tb) == Qt::TopToolBarArea)
334 mainWindowLayout->registerUnifiedToolBarArea(tb, upper.y(), lower.y());
335 else
336 mainWindowLayout->registerUnifiedToolBarArea(tb, 0, 0);
337#endif
338}
339
340void QToolBarLayout::setGeometry(const QRect &rect)
341{
342 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
343 if (!tb)
344 return;
345 QStyle *style = tb->style();
346 QStyleOptionToolBar opt;
347 tb->initStyleOption(&opt);
348 const QMargins margins = contentsMargins();
349 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
350 Qt::Orientation o = tb->orientation();
351
352 QLayout::setGeometry(rect);
353
354 updateMacBorderMetrics();
355
356 bool ranOutOfSpace = false;
357 if (!animating)
358 ranOutOfSpace = layoutActions(rect.size());
359
360 if (expanded || animating || ranOutOfSpace) {
361 Qt::ToolBarArea area = Qt::TopToolBarArea;
362 if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget()))
363 area = win->toolBarArea(tb);
364 QSize hint = sizeHint();
365
366 QPoint pos;
367 rpick(o, pos) = pick(o, rect.bottomRight()) -
368 pick(o, QSize(margins.bottom(), margins.right())) - extensionExtent + 2;
369 if (area == Qt::LeftToolBarArea || area == Qt::TopToolBarArea)
370 rperp(o, pos) = perp(o, rect.topLeft()) +
371 perp(o, QSize(margins.top(), margins.left()));
372 else
373 rperp(o, pos) = perp(o, rect.bottomRight()) -
374 perp(o, QSize(margins.bottom(), margins.right())) -
375 (perp(o, hint) - perp(o, margins)) + 1;
376 QSize size;
377 rpick(o, size) = extensionExtent;
378 rperp(o, size) = perp(o, hint) - perp(o, margins);
379 QRect r(pos, size);
380
381 if (o == Qt::Horizontal)
382 r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
383
384 extension->setGeometry(r);
385
386 if (extension->isHidden())
387 extension->show();
388 } else {
389 if (!extension->isHidden())
390 extension->hide();
391 }
392}
393
394bool QToolBarLayout::layoutActions(const QSize &size)
395{
396 if (dirty)
397 updateGeomArray();
398
399 QRect rect(0, 0, size.width(), size.height());
400
401 QList<QWidget*> showWidgets, hideWidgets;
402
403 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
404 if (!tb)
405 return false;
406 QStyle *style = tb->style();
407 QStyleOptionToolBar opt;
408 tb->initStyleOption(&opt);
409 const int handleExtent = movable()
410 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
411 const QMargins margins = contentsMargins();
412 const int spacing = this->spacing();
413 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
414 Qt::Orientation o = tb->orientation();
415 bool extensionMenuContainsOnlyWidgetActions = true;
416
417 int space = pick(o, rect.size()) - pick(o, margins) - handleExtent;
418 if (space <= 0)
419 return false; // nothing to do.
420
421 if (popupMenu)
422 popupMenu->clear();
423
424 bool ranOutOfSpace = false;
425 int rows = 0;
426 int rowPos = perp(o, rect.topLeft()) + perp(o, QSize(margins.top(), margins.left()));
427 int i = 0;
428 while (i < items.size()) {
429 QList<QLayoutStruct> a = geomArray;
430
431 int start = i;
432 int size = 0;
433 int prev = -1;
434 int rowHeight = 0;
435 int count = 0;
436 int maximumSize = 0;
437 bool expansiveRow = false;
438 for (; i < items.size(); ++i) {
439 if (a[i].empty)
440 continue;
441
442 int newSize = size + (count == 0 ? 0 : spacing) + a[i].minimumSize;
443 if (prev != -1 && newSize > space) {
444 if (rows == 0)
445 ranOutOfSpace = true;
446 // do we have to move the previous item to the next line to make space for
447 // the extension button?
448 if (count > 1 && size + spacing + extensionExtent > space)
449 i = prev;
450 break;
451 }
452
453 if (expanded)
454 rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));
455 expansiveRow = expansiveRow || a[i].expansive;
456 size = newSize;
457 maximumSize += spacing + (a[i].expansive ? a[i].maximumSize : a[i].smartSizeHint());
458 prev = i;
459 ++count;
460 }
461
462 // stretch at the end
463 a[i].sizeHint = 0;
464 a[i].maximumSize = QWIDGETSIZE_MAX;
465 a[i].minimumSize = 0;
466 a[i].expansive = true;
467 a[i].stretch = 0;
468 a[i].empty = true;
469
470 if (expansiveRow && maximumSize < space) {
471 expansiveRow = false;
472 a[i].maximumSize = space - maximumSize;
473 }
474
475 qGeomCalc(a, start, i - start + (expansiveRow ? 0 : 1), 0,
476 space - (ranOutOfSpace ? (extensionExtent + spacing) : 0),
477 spacing);
478
479 for (int j = start; j < i; ++j) {
480 QToolBarItem *item = items.at(j);
481
482 if (a[j].empty) {
483 if (!item->widget()->isHidden())
484 hideWidgets << item->widget();
485 continue;
486 }
487
488 QPoint pos;
489 rpick(o, pos) = pick(o, QSize(margins.top(), margins.left())) + handleExtent + a[j].pos;
490 rperp(o, pos) = rowPos;
491 QSize size;
492 rpick(o, size) = a[j].size;
493 if (expanded)
494 rperp(o, size) = rowHeight;
495 else
496 rperp(o, size) = perp(o, rect.size()) - perp(o, margins);
497 QRect r(pos, size);
498
499 if (o == Qt::Horizontal)
500 r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
501
502 item->setGeometry(r);
503
504 if (item->widget()->isHidden())
505 showWidgets << item->widget();
506 }
507
508 if (!expanded) {
509 for (int j = i; j < items.size(); ++j) {
510 QToolBarItem *item = items.at(j);
511 if (!item->widget()->isHidden())
512 hideWidgets << item->widget();
513 if (popupMenu) {
514 if (!defaultWidgetAction(item)) {
515 popupMenu->addAction(item->action);
516 extensionMenuContainsOnlyWidgetActions = false;
517 }
518 }
519 }
520 break;
521 }
522
523 rowPos += rowHeight + spacing;
524 ++rows;
525 }
526
527 // if we are using a popup menu, not the expadning toolbar effect, we cannot move custom
528 // widgets into the menu. If only custom widget actions are chopped off, the popup menu
529 // is empty. So we show the little extension button to show something is chopped off,
530 // but we make it disabled.
531 extension->setEnabled(popupMenu == nullptr || !extensionMenuContainsOnlyWidgetActions);
532
533 // we have to do the show/hide here, because it triggers more calls to setGeometry :(
534 for (int i = 0; i < showWidgets.size(); ++i)
535 showWidgets.at(i)->show();
536 for (int i = 0; i < hideWidgets.size(); ++i)
537 hideWidgets.at(i)->hide();
538
539 return ranOutOfSpace;
540}
541
542QSize QToolBarLayout::expandedSize(const QSize &size) const
543{
544 if (dirty)
545 updateGeomArray();
546
547 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
548 if (!tb)
549 return QSize(0, 0);
550 QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget());
551 Qt::Orientation o = tb->orientation();
552 QStyle *style = tb->style();
553 QStyleOptionToolBar opt;
554 tb->initStyleOption(&opt);
555 const int handleExtent = movable()
556 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
557 const QMargins margins = contentsMargins();
558 const int spacing = this->spacing();
559 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
560
561 int total_w = 0;
562 int count = 0;
563 for (int x = 0; x < items.size(); ++x) {
564 if (!geomArray[x].empty) {
565 total_w += (count == 0 ? 0 : spacing) + geomArray[x].minimumSize;
566 ++count;
567 }
568 }
569 if (count == 0)
570 return QSize(0, 0);
571
572 int min_w = pick(o, size);
573 int rows = (int)qSqrt(qreal(count));
574 if (rows == 1)
575 ++rows; // we want to expand to at least two rows
576 int space = total_w/rows + spacing + extensionExtent;
577 space = qMax(space, min_w - pick(o, margins) - handleExtent);
578 if (win != nullptr)
579 space = qMin(space, pick(o, win->size()) - pick(o, margins) - handleExtent);
580
581 int w = 0;
582 int h = 0;
583 int i = 0;
584 while (i < items.size()) {
585 int count = 0;
586 int size = 0;
587 int prev = -1;
588 int rowHeight = 0;
589 for (; i < items.size(); ++i) {
590 if (geomArray[i].empty)
591 continue;
592
593 int newSize = size + (count == 0 ? 0 : spacing) + geomArray[i].minimumSize;
594 rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));
595 if (prev != -1 && newSize > space) {
596 if (count > 1 && size + spacing + extensionExtent > space) {
597 size -= spacing + geomArray[prev].minimumSize;
598 i = prev;
599 }
600 break;
601 }
602
603 size = newSize;
604 prev = i;
605 ++count;
606 }
607
608 w = qMax(size, w);
609 h += rowHeight + spacing;
610 }
611
612 w += pick(Qt::Horizontal, margins) + handleExtent + spacing + extensionExtent;
613 w = qMax(w, min_w);
614 if (win != nullptr)
615 w = qMin(w, pick(o, win->size()));
616 h += pick(Qt::Vertical, margins) - spacing; //there is no spacing before the first row
617
618 QSize result;
619 rpick(o, result) = w;
620 rperp(o, result) = h;
621 return result;
622}
623
624void QToolBarLayout::setExpanded(bool exp)
625{
626 QWidget *tb = qobject_cast<QToolBar*>(parentWidget());
627 if (!tb)
628 return;
629 if (exp == expanded && !tb->isWindow())
630 return;
631
632 expanded = exp;
633 extension->setChecked(expanded);
634
635 if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) {
636#if !QT_CONFIG(dockwidget)
637 animating = false;
638#else
639 animating = !tb->isWindow() && win->isAnimated();
640#endif
641 QMainWindowLayout *layout = qt_mainwindow_layout(win);
642 if (expanded) {
643 tb->raise();
644 } else {
645 QList<int> path = layout->layoutState.indexOf(tb);
646 if (!path.isEmpty()) {
647 QRect rect = layout->layoutState.itemRect(path);
648 layoutActions(rect.size());
649 }
650 }
651 const auto rule = animating ? QWidgetAnimator::AnimationRule::Run
652 : QWidgetAnimator::AnimationRule::Stop;
653 layout->layoutState.toolBarAreaLayout.apply(rule);
654 }
655}
656
657QSize QToolBarLayout::minimumSize() const
658{
659 if (dirty)
660 updateGeomArray();
661 return minSize;
662}
663
664QSize QToolBarLayout::sizeHint() const
665{
666 if (dirty)
667 updateGeomArray();
668 return hint;
669}
670
671QToolBarItem *QToolBarLayout::createItem(QAction *action)
672{
673 bool customWidget = false;
674 bool standardButtonWidget = false;
675 QWidget *widget = nullptr;
676 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());
677 if (!tb)
678 return (QToolBarItem *)nullptr;
679
680 if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action)) {
681 widget = widgetAction->requestWidget(tb);
682 if (widget != nullptr) {
683 widget->setAttribute(Qt::WA_LayoutUsesWidgetRect);
684 customWidget = true;
685 }
686 } else if (action->isSeparator()) {
687 QToolBarSeparator *sep = new QToolBarSeparator(tb);
688 connect(tb, SIGNAL(orientationChanged(Qt::Orientation)),
689 sep, SLOT(setOrientation(Qt::Orientation)));
690 widget = sep;
691 }
692
693 if (!widget) {
694 QToolButton *button = new QToolButton(tb);
695 button->setAutoRaise(true);
696 button->setFocusPolicy(Qt::NoFocus);
697 button->setIconSize(tb->iconSize());
698 button->setToolButtonStyle(tb->toolButtonStyle());
699 QObject::connect(tb, SIGNAL(iconSizeChanged(QSize)),
700 button, SLOT(setIconSize(QSize)));
701 QObject::connect(tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
702 button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
703 button->setDefaultAction(action);
704 QObject::connect(button, SIGNAL(triggered(QAction*)), tb, SIGNAL(actionTriggered(QAction*)));
705 widget = button;
706 standardButtonWidget = true;
707 }
708
709 widget->hide();
710 QToolBarItem *result = new QToolBarItem(widget);
711 if (standardButtonWidget)
712 result->setAlignment(Qt::AlignJustify);
713 result->customWidget = customWidget;
714 result->action = action;
715 return result;
716}
717
718QT_END_NAMESPACE
719
720#include "moc_qtoolbarlayout_p.cpp"
bool isEmpty() const override
Implemented in subclasses to return whether this item is empty, i.e.
QToolBarItem(QWidget *widget)
Combined button and popup list for selecting options.
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
static bool defaultWidgetAction(QToolBarItem *item)