QtCanpool 3.3.0
载入中...
搜索中...
未找到
qxtoolbutton.cpp
浏览该文件的文档.
1
5#include "qxtoolbutton.h"
6
7#include <QMouseEvent>
8#include "qtcompat/qtcompat.h"
9#include <QPaintEvent>
10#include <QStyleOption>
11#include <QStyleOptionFocusRect>
12#include <QStyleOptionToolButton>
13#include <QStylePainter>
14#include <QApplication>
15#include <QAction>
16#include <QMenu>
17
19
20class QxToolButtonPrivate
21{
22public:
23 QxToolButtonPrivate();
24
25 QStyle *style() const;
26 QStyle::PrimitiveElement indicatorArrowType() const;
27 int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *toolbutton, const QWidget *widget) const;
28
29 void drawArrow(const QStyleOptionToolButton *toolbutton, const QRect &rect, QPainter *painter,
30 const QWidget *w) const;
31
32 void splitString(const QString &str, QString &strFirstRow, QString &strSecondRow) const;
33 void drawToolButton(const QStyleOptionToolButton *opt, QPainter *p, const QWidget *widget);
34 void drawToolButtonLabel(const QStyleOption *opt, QPainter *p, const QWidget *w);
35 QRect subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QStyle::SubControl sc,
36 const QWidget *widget) const;
37
38 bool hasMenu(const QStyleOptionToolButton *toolbutton) const;
39public:
40 Qt::ArrowType m_menuArrowType;
41 QxToolButton::MenuArea m_menuArea;
42 QRect m_iconRect;
43 QRect m_textRect;
44 QxToolButton *q;
45 bool m_showMenu;
46 bool m_forceCenter;
47 bool m_forceDefaultShowMenu;
48};
49
50QxToolButtonPrivate::QxToolButtonPrivate()
51 : m_menuArrowType(Qt::DownArrow)
52 , m_menuArea(QxToolButton::BottomMenuArea)
53 , m_showMenu(false)
54 , m_forceCenter(true)
55 , m_forceDefaultShowMenu(false)
56{
57}
58
59QStyle *QxToolButtonPrivate::style() const
60{
61 return q->style();
62}
63
64QStyle::PrimitiveElement QxToolButtonPrivate::indicatorArrowType() const
65{
66 switch (m_menuArrowType) {
67 case Qt::LeftArrow:
68 return QStyle::PE_IndicatorArrowLeft;
69 case Qt::RightArrow:
70 return QStyle::PE_IndicatorArrowRight;
71 case Qt::UpArrow:
72 return QStyle::PE_IndicatorArrowUp;
73 case Qt::DownArrow:
74 default:
75 return QStyle::PE_IndicatorArrowDown;
76 }
77}
78
79int QxToolButtonPrivate::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const
80{
81 // When using qstylesheet, mbi may be 0
82 int mbi = style()->pixelMetric(metric, opt, widget);
83 if (mbi <= 0) {
84 mbi = 10;
85 }
86 return mbi;
87}
88
89void QxToolButtonPrivate::drawArrow(const QStyleOptionToolButton *toolbutton, const QRect &rect, QPainter *p,
90 const QWidget *w) const
91{
92 QStyle::PrimitiveElement pe;
93
94 switch (toolbutton->arrowType) {
95 case Qt::LeftArrow:
96 pe = QStyle::PE_IndicatorArrowLeft;
97 break;
98 case Qt::RightArrow:
99 pe = QStyle::PE_IndicatorArrowRight;
100 break;
101 case Qt::UpArrow:
102 pe = QStyle::PE_IndicatorArrowUp;
103 break;
104 case Qt::DownArrow:
105 pe = QStyle::PE_IndicatorArrowDown;
106 break;
107 default:
108 return;
109 }
110
111 QStyleOptionToolButton arrowOpt;
112 arrowOpt.rect = rect;
113 arrowOpt.palette = toolbutton->palette;
114 arrowOpt.state = toolbutton->state;
115 style()->drawPrimitive(pe, &arrowOpt, p, w);
116}
117
118void QxToolButtonPrivate::splitString(const QString &str, QString &strFirstRow, QString &strSecondRow) const
119{
120 strFirstRow = str;
121 strSecondRow.clear();
122
123 QStringList strList = str.split('\n');
124 if (strList.count() == 1) {
125 return;
126 }
127 strFirstRow = strList.at(0);
128 strSecondRow = strList.at(1);
129}
130
131void QxToolButtonPrivate::drawToolButton(const QStyleOptionToolButton *opt, QPainter *p, const QWidget *widget)
132{
133 const QStyleOptionToolButton *toolbutton = opt;
134 QRect menuarea;
135 menuarea = subControlRect(QStyle::CC_ToolButton, toolbutton, QStyle::SC_ToolButtonMenu, widget);
136
137 QStyle::State bflags = toolbutton->state & ~QStyle::State_Sunken;
138 if (bflags & QStyle::State_AutoRaise) {
139 if (!(bflags & QStyle::State_MouseOver) || !(bflags & QStyle::State_Enabled))
140 bflags &= ~QStyle::State_Raised;
141 }
142 QStyle::State mflags = bflags;
143 if (toolbutton->state & QStyle::State_Sunken) {
144 if (toolbutton->activeSubControls & QStyle::SC_ToolButton)
145 bflags |= QStyle::State_Sunken;
146 mflags |= QStyle::State_Sunken;
147 }
148
149 // draw tool
150 style()->drawPrimitive(QStyle::PE_PanelButtonTool, toolbutton, p, widget);
151
152 if (toolbutton->state & QStyle::State_HasFocus) {
153 QStyleOptionFocusRect fr;
154 fr.QStyleOption::operator=(*toolbutton);
155 fr.rect.adjust(3, 3, -3, -3);
156 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
157 fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, widget), 0);
158 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &fr, p, widget);
159 }
160
161 // draw label and icon
162 QStyleOptionToolButton label = *toolbutton;
163 label.state = bflags;
164 drawToolButtonLabel(&label, p, widget);
165
166 // draw arraw
167 if (toolbutton->subControls & QStyle::SC_ToolButtonMenu) {
168 QStyleOption tool(0);
169 tool.palette = toolbutton->palette;
170
171 QRect ir = menuarea;
172 QRect rcArrow;
173
174 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon && m_menuArea == QxToolButton::BottomMenuArea) {
175 QString strFirstRow, strSecondRow;
176 splitString(toolbutton->text, strFirstRow, strSecondRow);
177 int height = toolbutton->fontMetrics.height();
178 int mbi = 6;
179 rcArrow =
180 QRect(QPoint(strSecondRow.isEmpty() ? toolbutton->rect.width() / 2 - 2 : toolbutton->rect.right() - 7,
181 m_textRect.top() + height * 3 / 2 - mbi / 2),
182 QSize(mbi, mbi));
183 } else {
184 int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, widget);
185 rcArrow = QRect(ir.right() - mbi - 1,
186 toolbutton->rect.top() + (ir.height() - mbi) / 2 + ((ir.height() - mbi) % 2), mbi, mbi);
187 }
188 tool.rect = rcArrow;
189 tool.state = mflags;
190 style()->drawPrimitive(indicatorArrowType(), &tool, p, widget);
191 } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
192 QStyleOptionToolButton newBtn = *toolbutton;
193 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon && m_menuArea == QxToolButton::BottomMenuArea) {
194 QString strFirstRow, strSecondRow;
195 splitString(toolbutton->text, strFirstRow, strSecondRow);
196 int height = toolbutton->fontMetrics.height();
197 int mbi = 6;
198 newBtn.rect =
199 QRect(QPoint(strSecondRow.isEmpty() ? toolbutton->rect.width() / 2 - 2 : toolbutton->rect.right() - 8,
200 m_textRect.top() + height * 3 / 2 - mbi / 2),
201 QSize(mbi, mbi));
202 } else {
203 QRect ir = menuarea;
204 int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, widget);
205 newBtn.rect = QRect(ir.right() - mbi - 1,
206 toolbutton->rect.top() + (ir.height() - mbi) / 2 + ((ir.height() - mbi) % 2), mbi, mbi);
207 }
208 style()->drawPrimitive(indicatorArrowType(), &newBtn, p, widget);
209 }
210}
211
212void QxToolButtonPrivate::drawToolButtonLabel(const QStyleOption *opt, QPainter *p, const QWidget *w)
213{
214 const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(opt);
215 QRect rect = toolbutton->rect;
216 p->setFont(toolbutton->font);
217
218 m_iconRect = QRect();
219 m_textRect = QRect();
220
221 // Arrow type always overrules and is always shown
222 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
223 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty()) ||
224 toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
225 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
226 if (!style()->styleHint(QStyle::SH_UnderlineShortcut, opt, w))
227 alignment |= Qt::TextHideMnemonic;
228 QRect rectText = rect;
229 if (hasMenu(toolbutton)) {
230 int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, opt, w);
231 rectText.adjust(0, 0, -mbi, 0);
232 }
233 m_textRect = rectText;
234 style()->drawItemText(p, rect, alignment, toolbutton->palette, opt->state & QStyle::State_Enabled,
235 toolbutton->text, QPalette::ButtonText);
236 } else { // !Qt::ToolButtonTextOnly
237 QPixmap pm;
238 QSize pmSize = toolbutton->iconSize;
239 if (pmSize.width() > qMin(rect.width(), rect.height())) {
240 const int iconExtent = style()->pixelMetric(QStyle::PM_SmallIconSize);
241 pmSize = QSize(iconExtent, iconExtent);
242 }
243
244 if (!toolbutton->icon.isNull()) {
245 QIcon::State state = toolbutton->state & QStyle::State_On ? QIcon::On : QIcon::Off;
246 QIcon::Mode mode;
247 if (!(toolbutton->state & QStyle::State_Enabled)) {
248 mode = QIcon::Disabled;
249 } else if ((opt->state & QStyle::State_MouseOver) && (opt->state & QStyle::State_AutoRaise)) {
250 mode = QIcon::Active;
251 } else {
252 mode = QIcon::Normal;
253 }
254 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(pmSize), mode, state);
255 pmSize = pm.size() / pm.devicePixelRatio();
256 }
257
258 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
259 p->setFont(toolbutton->font);
260 QRect pr = rect, tr = rect;
261
262 int alignment = Qt::TextShowMnemonic;
263 if (!style()->styleHint(QStyle::SH_UnderlineShortcut, opt, w))
264 alignment |= Qt::TextHideMnemonic;
265
266 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
267 pr.setHeight(pmSize.height() + 6);
268 tr.adjust(0, pr.height() - 1, 0, -3);
269 if (!hasArrow) {
270 style()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
271 } else {
272 drawArrow(toolbutton, pr, p, w);
273 }
274 alignment |= Qt::AlignCenter;
275 } else { // ToolButtonTextBesideIcon, ..
276 pr.setWidth(pmSize.width() + 8);
277 tr.adjust(pr.width(), 0, 0, 0);
278 if (!hasArrow) {
279 style()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
280 } else {
281 drawArrow(toolbutton, pr, p, w);
282 }
283 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
284 }
285
286 QRect rcText(QStyle::visualRect(opt->direction, rect, tr));
287 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
288 QString strFirstRow, strSecondRow;
289 splitString(toolbutton->text, strFirstRow, strSecondRow);
290
291 int height = toolbutton->fontMetrics.height();
292 // text AlignTop
293 QRect rcFirstRowText(QPoint(rcText.left(), rcText.top() + 1),
294 QPoint(rcText.right(), rcText.top() + height + 1));
295
296 // if QxToolButton::BottomMenuArea, add height in sizeHint
297 if (m_menuArea != QxToolButton::BottomMenuArea && strSecondRow.isEmpty()) {
298 rcFirstRowText = rcText;
299 }
300
301 if (!strFirstRow.isEmpty()) {
302 style()->drawItemText(p, rcFirstRowText, alignment, toolbutton->palette,
303 toolbutton->state & QStyle::State_Enabled, strFirstRow, QPalette::ButtonText);
304 }
305
306 if (!strSecondRow.isEmpty()) {
307 int left = rcText.left();
308 if (toolbutton->subControls & QStyle::SC_ToolButtonMenu ||
309 toolbutton->features & QStyleOptionToolButton::HasMenu)
310 left = opt->rect.left() - 5;
311
312 // text AlignTop
313 QRect rcSecondRowText(QPoint(left, rcText.top() + height + 1),
314 QPoint(rcText.right(), rcText.top() + height * 2 + 2));
315 style()->drawItemText(p, rcSecondRowText, alignment, toolbutton->palette,
316 toolbutton->state & QStyle::State_Enabled, strSecondRow,
317 QPalette::ButtonText);
318 }
319 } else { // ToolButtonTextBesideIcon, ..
320 style()->drawItemText(p, rcText, alignment, toolbutton->palette,
321 toolbutton->state & QStyle::State_Enabled, toolbutton->text,
322 QPalette::ButtonText);
323 }
324 m_iconRect = pr;
325 m_textRect = rcText;
326 } else { // ToolButtonIconOnly
327 QRect pr = rect;
328 if (hasMenu(toolbutton)) {
329 int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, opt, w);
330 pr.setWidth(pr.width() - mbi);
331 }
332 m_iconRect = pr;
333 if (hasArrow) {
334 drawArrow(toolbutton, rect, p, w);
335 } else {
336 QRect ir = m_forceCenter ? rect : m_iconRect;
337 style()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
338 }
339 }
340 }
341}
342
343QRect QxToolButtonPrivate::subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt,
344 QStyle::SubControl sc, const QWidget *widget) const
345{
346 switch (cc) {
347 case QStyle::CC_ToolButton:
348 if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
349 int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, tb, widget);
350 QRect ret = tb->rect;
351 switch (sc) {
352 case QStyle::SC_ToolButton:
353 if ((tb->features & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay)) ==
354 QStyleOptionToolButton::MenuButtonPopup)
355 ret.adjust(0, 0, -mbi, 0);
356 break;
357 case QStyle::SC_ToolButtonMenu:
358 if ((tb->features & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay)) ==
359 QStyleOptionToolButton::MenuButtonPopup)
360 ret.adjust(ret.width() - mbi - 2, 0, 0, 0);
361 break;
362 default:
363 break;
364 }
365 return style()->visualRect(tb->direction, tb->rect, ret);
366 }
367 break;
368 default:
369 break;
370 }
371 return style()->subControlRect(cc, opt, sc, widget);
372}
373
374bool QxToolButtonPrivate::hasMenu(const QStyleOptionToolButton *toolbutton) const
375{
376 if ((toolbutton->subControls & QStyle::SC_ToolButtonMenu) ||
377 (toolbutton->features & QStyleOptionToolButton::HasMenu)) {
378 return true;
379 }
380 return false;
381}
382
383QxToolButton::QxToolButton(QWidget *parent)
384 : QToolButton(parent)
385 , d(new QxToolButtonPrivate())
386{
387 d->q = this;
388 setAttribute(Qt::WA_StyledBackground, true);
389 setAutoRaise(true);
390 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
391}
392
393QxToolButton::QxToolButton(const QString &text, QWidget *parent)
394 : QxToolButton(parent)
395{
396 setText(text);
397}
398
399QxToolButton::QxToolButton(const QIcon &icon, const QString &text, QWidget *parent)
400 : QxToolButton(parent)
401{
402 setIcon(icon);
403 setText(text);
404}
405
407{
408 delete d;
409}
410
411Qt::ArrowType QxToolButton::menuArrowType() const
412{
413 return d->m_menuArrowType;
414}
415
416void QxToolButton::setMenuArrowType(Qt::ArrowType type)
417{
418 if (d->m_menuArrowType == type) {
419 return;
420 }
421 d->m_menuArrowType = type;
422 if (isVisible()) {
423 update();
424 }
425}
426
428{
429 return d->m_menuArea;
430}
431
433{
434 if (d->m_menuArea == area || toolButtonStyle() != Qt::ToolButtonTextUnderIcon) {
435 return;
436 }
437 d->m_menuArea = area;
438 if (isVisible()) {
439 update();
440 }
441}
442
444{
445 QSize sz = QToolButton::sizeHint();
446 QStyleOptionToolButton opt;
447 initStyleOption(&opt);
448
449 int w = 0, h = 0;
450
451 QString textButton = opt.text;
452
453 if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) {
454 QSize icon = opt.iconSize;
455 QAction *action = defaultAction();
456 if (action && !action->icon().isNull())
457 icon = action->icon().actualSize(opt.iconSize);
458 w = icon.width();
459 h = icon.height();
460 }
461
462 bool indicatorCenter = false;
463 bool isBottomMenuArea = (menuArea() == QxToolButton::BottomMenuArea);
464 QToolButton::ToolButtonPopupMode mode = QToolButton::popupMode();
465
466 if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) {
467 if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
468 QString strFirstRow, strSecondRow;
469 d->splitString(textButton, strFirstRow, strSecondRow);
470
471 QSize textFirstSize;
472 if (!strFirstRow.isEmpty())
473 textFirstSize = opt.fontMetrics.size(Qt::TextShowMnemonic, strFirstRow);
474
475 if (!strSecondRow.isEmpty()) {
476 QSize textSecondSize = opt.fontMetrics.size(Qt::TextShowMnemonic, strSecondRow);
477 textFirstSize.setWidth(qMax(textFirstSize.width(), textSecondSize.width()));
478 }
479
480 h = sz.height();
481 if (isBottomMenuArea && strSecondRow.isEmpty()) {
482 indicatorCenter = opt.features & QStyleOptionToolButton::HasMenu;
483 h += opt.fontMetrics.height(); // place an empty text row
484 }
485
486 // if the text is more than icon
487 if (textFirstSize.width() > w)
488 w = textFirstSize.width();
489 // add pixel
490 w += mode == QToolButton::MenuButtonPopup ? 4 : 10;
491 } else {
492 // ToolButtonTextOnly, ToolButtonTextBesideIcon, ToolButtonFollowStyle
493 QSize textSize = opt.fontMetrics.size(Qt::TextShowMnemonic, textButton);
494#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
495 textSize.setWidth(textSize.width() + opt.fontMetrics.width(QLatin1Char(' ')) * 2);
496#else
497 textSize.setWidth(textSize.width() + opt.fontMetrics.horizontalAdvance(QLatin1Char(' ')) * 2);
498#endif
499 h = sz.height();
500
501 if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
502 w += textSize.width() + 6;
503
504 if (textSize.height() > h)
505 h = textSize.height();
506 } else { // ToolButtonTextOnly, ToolButtonFollowStyle
507 w = textSize.width() + 4;
508 }
509 }
510 } else {
511 // ToolButtonIconOnly
512 h = sz.height();
513 w = h;
514 if (d->hasMenu(&opt)) {
515 w += 1;
516 }
517 }
518
519 opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
520
521 if ((mode == QToolButton::MenuButtonPopup || d->hasMenu(&opt)) && !indicatorCenter) {
522 int mbi = d->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
523 w += mbi;
524 // increase width to center the display during vertical layout
525 if ((opt.toolButtonStyle != Qt::ToolButtonTextBesideIcon &&
526 opt.toolButtonStyle != Qt::ToolButtonTextUnderIcon) ||
527 (!isBottomMenuArea && opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon)) {
528 if (d->m_forceCenter) {
529 w += mbi * 2 / 3;
530 }
531 }
532 }
533
534#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
535 return QSize(w, h).expandedTo(QApplication::globalStrut());
536#else
537 return QSize(w, h);
538#endif
539}
540
542{
543 if (d->m_forceCenter == b) {
544 return;
545 }
546 d->m_forceCenter = b;
547
548 if (isVisible()) {
549 update();
550 }
551}
552
554{
555 if (d->m_forceDefaultShowMenu == b) {
556 return;
557 }
558 d->m_forceDefaultShowMenu = b;
559}
560
561void QxToolButton::setToolButtonStyle(Qt::ToolButtonStyle style)
562{
563 QToolButton::setToolButtonStyle(style);
564 if (style == Qt::ToolButtonTextUnderIcon) {
565 return;
566 }
567 if (d->m_menuArea == QxToolButton::RightMenuArea) {
568 return;
569 }
570 d->m_menuArea = QxToolButton::RightMenuArea;
571}
572
573void QxToolButton::paintEvent(QPaintEvent *event)
574{
575 Q_UNUSED(event);
576 QPainter p(this);
577 QStyleOptionToolButton opt;
578 initStyleOption(&opt);
579 if (d->m_showMenu) {
580 opt.state |= QStyle::State_Sunken | QStyle::State_Raised;
581 }
582 d->drawToolButton(&opt, &p, this);
583}
584
586{
587 if (e->button() == Qt::LeftButton && popupMode() == MenuButtonPopup) {
588 if (d->m_forceDefaultShowMenu) {
589 QRect outRect = d->m_iconRect;
590 if (toolButtonStyle() == Qt::ToolButtonTextOnly) {
591 outRect = d->m_textRect;
592 }
593 if (outRect.isValid() && !outRect.contains(e->pos())) {
594 showMenu();
595 return;
596 }
597 } else {
598 // RightMenu popups menu on the right
599 if (d->m_menuArea == RightMenuArea && d->m_menuArrowType == Qt::RightArrow) {
600 QStyleOptionToolButton opt;
601 initStyleOption(&opt);
602 QRect popupr = d->subControlRect(QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButtonMenu, this);
603 if (popupr.isValid() && popupr.contains(e->pos())) {
604 QAction *action = defaultAction();
605 if (action && action->menu()) {
606 d->m_showMenu = true;
607 repaint();
608 QPoint pos = QtCanpoolCompat::globalMousePos(e);
609 pos.setX(pos.x() - e->pos().x() + width());
610 pos.setY(pos.y() - e->pos().y());
611 action->menu()->exec(pos);
612 d->m_showMenu = false;
613 repaint();
614 return;
615 }
616 }
617 }
618 }
619 }
620 QToolButton::mousePressEvent(e);
621}
622
QSize sizeHint() const override
void setMenuArea(MenuArea area)
void setToolButtonStyle(Qt::ToolButtonStyle style)
void paintEvent(QPaintEvent *event) override
MenuArea menuArea() const
void setForceAlignCenter(bool b=true)
Qt::ArrowType menuArrowType() const
void mousePressEvent(QMouseEvent *e) override
void setForceDefaultShowMenu(bool b=false)
QxToolButton(QWidget *parent=nullptr)
void setMenuArrowType(Qt::ArrowType type)
QPoint globalMousePos(const QMouseEvent *event)
Definition qtcompat.h:26
#define QX_APP_END_NAMESPACE
#define QX_APP_BEGIN_NAMESPACE
QColor text