Utils: Add push button with menu and default click action

QPushButton has the functionality of setting a menu, but that replaces
the normal "click" functionality, and always opens the menu on click.

QToolButton can have a menu and the user can still click on it to just
click. But, QToolButton looks very different, and in combination with
other, normal push buttons very alien.

Create a push button that only shows the menu when clicking on/near the
menu indicator, and otherwise just sends the clicked() signal like a
non-menu push button.

Change-Id: Id6ba367e40c370275f67f0fbf77521c2e974b3b8
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2022-11-29 10:30:11 +01:00
parent 69ce2a4047
commit a499058a6f
4 changed files with 122 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "utils_global.h"
#include <QPushButton>
QT_BEGIN_NAMESPACE
class QMenu;
class QMouseEvent;
QT_END_NAMESPACE
namespace Utils {
class QTCREATOR_UTILS_EXPORT OptionPushButton : public QPushButton
{
Q_OBJECT
public:
OptionPushButton(QWidget *parent = nullptr);
OptionPushButton(const QString &text, QWidget *parent = nullptr);
void setOptionalMenu(QMenu *menu);
protected:
void mouseReleaseEvent(QMouseEvent *event) override;
};
} // namespace Utils