提交 b8547aa8 编写于 作者: J jp9000

UI: Add menu button (split button) class

When you assign a menu to a normal QPushButton, it becomes a button that
only allows you to have a menu.  This class lets you click the button
and have a menu at the same time.
上级 370761ba
......@@ -117,6 +117,7 @@ set(obs_SOURCES
window-remux.cpp
properties-view.cpp
focus-list.cpp
menu-button.cpp
double-slider.cpp
volume-control.cpp
adv-audio-control.cpp
......@@ -159,6 +160,7 @@ set(obs_HEADERS
display-helpers.hpp
double-slider.hpp
focus-list.hpp
menu-button.hpp
mute-checkbox.hpp
volume-control.hpp
adv-audio-control.hpp
......
#include <QMenu>
#include <QKeyEvent>
#include <QMouseEvent>
#include "menu-button.hpp"
void MenuButton::keyPressEvent(QKeyEvent *event)
{
if (menu()) {
switch (event->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
emit clicked();
return;
case Qt::Key_Down:
showMenu();
return;
}
}
QPushButton::keyPressEvent(event);
}
void MenuButton::mousePressEvent(QMouseEvent *event)
{
if (menu()) {
if (width() - event->x() <= 15)
showMenu();
else
setDown(true);
} else {
QPushButton::mousePressEvent(event);
}
}
#pragma once
#include <QPushButton>
class MenuButton : public QPushButton {
Q_OBJECT
protected:
void mousePressEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
public:
explicit inline MenuButton(QWidget *parent = nullptr)
: QPushButton(parent)
{
}
explicit inline MenuButton(const QString &text,
QWidget *parent = nullptr)
: QPushButton(text, parent)
{
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册