forked from qt-creator/qt-creator
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:
31
src/libs/utils/optionpushbutton.h
Normal file
31
src/libs/utils/optionpushbutton.h
Normal 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
|
||||
Reference in New Issue
Block a user