Remove mousebuttons examples
The example didn't show anything useful, and seemed more like a manual test case. Change-Id: Ia71f39b26943aab04b6895e63b6eed50dd084bfd Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit 2951f72584e70ddf31c1ef644f7eb8643da0084b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d93e748a88
commit
1fcfb6dd4b
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
@ -1,70 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// Copyright (C) 2016 Rick Stockton <rickstockton@reno-computerhelp.com>
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\example widgets/mousebuttons
|
|
||||||
\title Mouse Button Tester
|
|
||||||
|
|
||||||
\brief The 'Mouse Button Tester' example demonstrates how to reimplement
|
|
||||||
mouse events within a custom class. You can also use this program to
|
|
||||||
verify that Qt is actually receiving mouse events from your mouse.
|
|
||||||
|
|
||||||
Many 'gamer' mouse devices are configured with high-numbered "buttons"
|
|
||||||
sending text shortcuts for certain games. With such a mouse, no mouse
|
|
||||||
button events occur: The "mouse" sends keystrokes, and the
|
|
||||||
'Mouse Button Tester' Window will not see the event. Receiving no event,
|
|
||||||
it will not repaint the Window with new text describing a button event.
|
|
||||||
|
|
||||||
And so, in addition to it's use as Qt example code, the program may be
|
|
||||||
useful s a mouse device tester. Note that there is another example
|
|
||||||
mouse buttons example which provides the same function, written in QML.
|
|
||||||
|
|
||||||
This program (the Widget-based example) consists of three classes,
|
|
||||||
in addition to the main() parent program:
|
|
||||||
|
|
||||||
\list
|
|
||||||
\li \c A QPushButton, "Quit".
|
|
||||||
\li \c ButtonTester. This is derived from Qt's TextArea class, for
|
|
||||||
purpose of customizing/re-implementing the mouse and wheel event
|
|
||||||
member functions.
|
|
||||||
\li \c A simple QVBoxLayout layout.
|
|
||||||
\endlist
|
|
||||||
|
|
||||||
First we will review the main program, with it's layout and "Quit"
|
|
||||||
QPushButton. Then we will take a look at the \c ButtonTester class.
|
|
||||||
|
|
||||||
\section1 The Main Program
|
|
||||||
|
|
||||||
Note that the QPushButton, "Quit", is defined directly within the main()
|
|
||||||
program, rather than another class. This is a correct way of defining a
|
|
||||||
"Quit" QPushButton: A "Quit" Button defined inside another
|
|
||||||
class would result in the destructor of that second class being
|
|
||||||
called twice. This "Quit" Button uses the traditional Signal/Slot
|
|
||||||
connection to invoke termination of the QApp, which will properly destroy
|
|
||||||
its child classes before terminating itself.
|
|
||||||
|
|
||||||
The remainder of the main() program is concerned with defining the layout,
|
|
||||||
and applying a minimum size to the customized ButtonTester.
|
|
||||||
|
|
||||||
\section1 ButtonTester Class Definition
|
|
||||||
|
|
||||||
The \c ButtonTester class inherits from QTextEdit, and listens for
|
|
||||||
mouse events on all possible Qt::MouseButton values. It also listens for
|
|
||||||
wheel events from the mouse, and indicates the direction of wheel motion
|
|
||||||
("up", down", "left", or "right"). It prints short debug messages into
|
|
||||||
the Window, and also on the console QDebug() stream, when mouse button
|
|
||||||
and wheel events occur. Our reimplementation of mousePressEvent(),
|
|
||||||
mouseReleaseEvent(), mouseDoubleClickEvent(), and wheelEvent() "drive"
|
|
||||||
the program; the other functions simply convert the Qt::MouseButton
|
|
||||||
values into text strings.
|
|
||||||
|
|
||||||
You should call the ignore() function on any mouse event (or other event)
|
|
||||||
which your widget-based classes do not use and consume. This function
|
|
||||||
assures that Qt will propagate the event through each parent widget,
|
|
||||||
until it is used or propagated to the Window Manager. (Qt attempts to do
|
|
||||||
this automatically, but it is better programming practice to explicitly
|
|
||||||
invoke the function.)
|
|
||||||
|
|
||||||
\image mousebutton-buttontester.png
|
|
||||||
*/
|
|
@ -15,7 +15,6 @@ qt_internal_add_example(lineedits)
|
|||||||
if(QT_FEATURE_movie)
|
if(QT_FEATURE_movie)
|
||||||
qt_internal_add_example(movie)
|
qt_internal_add_example(movie)
|
||||||
endif()
|
endif()
|
||||||
qt_internal_add_example(mousebuttons)
|
|
||||||
qt_internal_add_example(scribble)
|
qt_internal_add_example(scribble)
|
||||||
qt_internal_add_example(shapedclock)
|
qt_internal_add_example(shapedclock)
|
||||||
qt_internal_add_example(shortcuteditor)
|
qt_internal_add_example(shortcuteditor)
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
# Copyright (C) 2022 The Qt Company Ltd.
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.16)
|
|
||||||
project(mousebuttons LANGUAGES CXX)
|
|
||||||
|
|
||||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
|
||||||
set(INSTALL_EXAMPLESDIR "examples")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/mousebuttons")
|
|
||||||
|
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
|
||||||
|
|
||||||
qt_standard_project_setup()
|
|
||||||
|
|
||||||
qt_add_executable(mousebuttons
|
|
||||||
buttontester.cpp buttontester.h
|
|
||||||
main.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(mousebuttons PROPERTIES
|
|
||||||
WIN32_EXECUTABLE TRUE
|
|
||||||
MACOSX_BUNDLE TRUE
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(mousebuttons PRIVATE
|
|
||||||
Qt6::Core
|
|
||||||
Qt6::Gui
|
|
||||||
Qt6::Widgets
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS mousebuttons
|
|
||||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
|
||||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
|
||||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
|
||||||
)
|
|
@ -1,184 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// Copyright (C) 2016 Rick Stockton <rickstockton@reno-computerhelp.com>
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
||||||
|
|
||||||
#include "buttontester.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
void ButtonTester::mousePressEvent(QMouseEvent *e)
|
|
||||||
{
|
|
||||||
int j = ButtonTester::buttonByNumber (e->button());
|
|
||||||
QString result = "Mouse Press: raw button=" + QString::number(j)
|
|
||||||
+ " Qt=" + enumNameFromValue(e->button());
|
|
||||||
QString buttonsString = ButtonTester::enumNamesFromMouseButtons(e->buttons());
|
|
||||||
result += "\n heldbuttons " + buttonsString;
|
|
||||||
qDebug() << result;
|
|
||||||
this->setText(result);
|
|
||||||
this->repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ButtonTester::mouseReleaseEvent(QMouseEvent *e)
|
|
||||||
{
|
|
||||||
int j = ButtonTester::buttonByNumber (e->button());
|
|
||||||
QString result = "Mouse Release: raw button=" + QString::number(j)
|
|
||||||
+ " Qt=" + enumNameFromValue(e->button());
|
|
||||||
QString buttonsString = ButtonTester::enumNamesFromMouseButtons(e->buttons());
|
|
||||||
result += "\n heldbuttons " + buttonsString;
|
|
||||||
qDebug() << result;
|
|
||||||
this->setText(result);
|
|
||||||
this->repaint();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e)
|
|
||||||
{
|
|
||||||
int j = ButtonTester::buttonByNumber (e->button());
|
|
||||||
QString result = "Mouse DoubleClick: raw button=" + QString::number(j)
|
|
||||||
+ " Qt=" + enumNameFromValue(e->button());
|
|
||||||
QString buttonsString = ButtonTester::enumNamesFromMouseButtons(e->buttons());
|
|
||||||
result += "\n heldbuttons" + buttonsString;
|
|
||||||
qDebug() << result;
|
|
||||||
this->setText(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if QT_CONFIG(wheelevent)
|
|
||||||
void ButtonTester::wheelEvent (QWheelEvent *e)
|
|
||||||
{
|
|
||||||
QString result;
|
|
||||||
const bool vertical = qAbs(e->angleDelta().y()) >= qAbs(e->angleDelta().x());
|
|
||||||
const int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
|
|
||||||
if (delta > 0) {
|
|
||||||
if (vertical) {
|
|
||||||
result = "Mouse Wheel Event: UP";
|
|
||||||
} else {
|
|
||||||
result = "Mouse Wheel Event: LEFT";
|
|
||||||
}
|
|
||||||
} else if (delta < 0) {
|
|
||||||
if (vertical) {
|
|
||||||
result = "Mouse Wheel Event: DOWN";
|
|
||||||
} else {
|
|
||||||
result = "Mouse Wheel Event: RIGHT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug() << result;
|
|
||||||
this->setText(result);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int ButtonTester::buttonByNumber(const Qt::MouseButton button)
|
|
||||||
{
|
|
||||||
if (button == Qt::NoButton) return 0;
|
|
||||||
if (button == Qt::LeftButton) return 1;
|
|
||||||
if (button == Qt::RightButton) return 2;
|
|
||||||
if (button == Qt::MiddleButton) return 3;
|
|
||||||
|
|
||||||
/* Please note that Qt Button #4 corresponds to button #8 on all
|
|
||||||
* platforms which EMULATE wheel events by creating button events
|
|
||||||
* (Button #4 = Scroll Up; Button #5 = Scroll Down; Button #6 = Scroll
|
|
||||||
* Left; and Button #7 = Scroll Right.) This includes X11, with both
|
|
||||||
* Xlib and XCB. So, the "raw button" for "Qt::BackButton" is
|
|
||||||
* usually described as "Button #8".
|
|
||||||
|
|
||||||
* If your platform supports "smooth scrolling", then, for the cases of
|
|
||||||
* Qt::BackButton and higher, this program will show "raw button" with a
|
|
||||||
* value which is too large. Subtract 4 to get the correct button ID for
|
|
||||||
* your platform.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (button == Qt::BackButton) return 8;
|
|
||||||
if (button == Qt::ForwardButton) return 9;
|
|
||||||
if (button == Qt::TaskButton) return 10;
|
|
||||||
if (button == Qt::ExtraButton4) return 11;
|
|
||||||
if (button == Qt::ExtraButton5) return 12;
|
|
||||||
if (button == Qt::ExtraButton6) return 13;
|
|
||||||
if (button == Qt::ExtraButton7) return 14;
|
|
||||||
if (button == Qt::ExtraButton8) return 15;
|
|
||||||
if (button == Qt::ExtraButton9) return 16;
|
|
||||||
if (button == Qt::ExtraButton10) return 17;
|
|
||||||
if (button == Qt::ExtraButton11) return 18;
|
|
||||||
if (button == Qt::ExtraButton12) return 19;
|
|
||||||
if (button == Qt::ExtraButton13) return 20;
|
|
||||||
if (button == Qt::ExtraButton14) return 21;
|
|
||||||
if (button == Qt::ExtraButton15) return 22;
|
|
||||||
if (button == Qt::ExtraButton16) return 23;
|
|
||||||
if (button == Qt::ExtraButton17) return 24;
|
|
||||||
if (button == Qt::ExtraButton18) return 25;
|
|
||||||
if (button == Qt::ExtraButton19) return 26;
|
|
||||||
if (button == Qt::ExtraButton20) return 27;
|
|
||||||
if (button == Qt::ExtraButton21) return 28;
|
|
||||||
if (button == Qt::ExtraButton22) return 29;
|
|
||||||
if (button == Qt::ExtraButton23) return 30;
|
|
||||||
if (button == Qt::ExtraButton24) return 31;
|
|
||||||
qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ButtonTester::enumNameFromValue(const Qt::MouseButton button)
|
|
||||||
{
|
|
||||||
if (button == Qt::NoButton) return "NoButton";
|
|
||||||
if (button == Qt::LeftButton) return "LeftButton";
|
|
||||||
if (button == Qt::RightButton) return "RightButton";
|
|
||||||
if (button == Qt::MiddleButton) return "MiddleButton";
|
|
||||||
if (button == Qt::BackButton) return "BackButton";
|
|
||||||
if (button == Qt::ForwardButton) return "ForwardButton";
|
|
||||||
if (button == Qt::TaskButton) return "TaskButton";
|
|
||||||
if (button == Qt::ExtraButton4) return "ExtraButton4";
|
|
||||||
if (button == Qt::ExtraButton5) return "ExtraButton5";
|
|
||||||
if (button == Qt::ExtraButton6) return "ExtraButton6";
|
|
||||||
if (button == Qt::ExtraButton7) return "ExtraButton7";
|
|
||||||
if (button == Qt::ExtraButton8) return "ExtraButton8";
|
|
||||||
if (button == Qt::ExtraButton9) return "ExtraButton9";
|
|
||||||
if (button == Qt::ExtraButton10) return "ExtraButton10";
|
|
||||||
if (button == Qt::ExtraButton11) return "ExtraButton11";
|
|
||||||
if (button == Qt::ExtraButton12) return "ExtraButton12";
|
|
||||||
if (button == Qt::ExtraButton13) return "ExtraButton13";
|
|
||||||
if (button == Qt::ExtraButton14) return "ExtraButton14";
|
|
||||||
if (button == Qt::ExtraButton15) return "ExtraButton15";
|
|
||||||
if (button == Qt::ExtraButton16) return "ExtraButton16";
|
|
||||||
if (button == Qt::ExtraButton17) return "ExtraButton17";
|
|
||||||
if (button == Qt::ExtraButton18) return "ExtraButton18";
|
|
||||||
if (button == Qt::ExtraButton19) return "ExtraButton19";
|
|
||||||
if (button == Qt::ExtraButton20) return "ExtraButton20";
|
|
||||||
if (button == Qt::ExtraButton21) return "ExtraButton21";
|
|
||||||
if (button == Qt::ExtraButton22) return "ExtraButton22";
|
|
||||||
if (button == Qt::ExtraButton23) return "ExtraButton23";
|
|
||||||
if (button == Qt::ExtraButton24) return "ExtraButton24";
|
|
||||||
qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value");
|
|
||||||
return "NoButton";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ButtonTester::enumNamesFromMouseButtons(const Qt::MouseButtons buttons)
|
|
||||||
{
|
|
||||||
QString returnText = "";
|
|
||||||
if (buttons == Qt::NoButton) return "NoButton";
|
|
||||||
if (buttons & Qt::LeftButton) returnText += "LeftButton ";
|
|
||||||
if (buttons & Qt::RightButton) returnText += "RightButton ";
|
|
||||||
if (buttons & Qt::MiddleButton) returnText += "MiddleButton ";
|
|
||||||
if (buttons & Qt::BackButton) returnText += "BackButton ";
|
|
||||||
if (buttons & Qt::ForwardButton) returnText += "ForwardButton ";
|
|
||||||
if (buttons & Qt::TaskButton) returnText += "TaskButton ";
|
|
||||||
if (buttons & Qt::ExtraButton4) returnText += "ExtraButton4 ";
|
|
||||||
if (buttons & Qt::ExtraButton5) returnText += "ExtraButton5 ";
|
|
||||||
if (buttons & Qt::ExtraButton6) returnText += "ExtraButton6 ";
|
|
||||||
if (buttons & Qt::ExtraButton7) returnText += "ExtraButton7 ";
|
|
||||||
if (buttons & Qt::ExtraButton8) returnText += "ExtraButton8 ";
|
|
||||||
if (buttons & Qt::ExtraButton9) returnText += "ExtraButton9 ";
|
|
||||||
if (buttons & Qt::ExtraButton10) returnText += "ExtraButton10 ";
|
|
||||||
if (buttons & Qt::ExtraButton11) returnText += "ExtraButton11 ";
|
|
||||||
if (buttons & Qt::ExtraButton12) returnText += "ExtraButton12 ";
|
|
||||||
if (buttons & Qt::ExtraButton13) returnText += "ExtraButton13 ";
|
|
||||||
if (buttons & Qt::ExtraButton14) returnText += "ExtraButton14 ";
|
|
||||||
if (buttons & Qt::ExtraButton15) returnText += "ExtraButton15 ";
|
|
||||||
if (buttons & Qt::ExtraButton16) returnText += "ExtraButton16 ";
|
|
||||||
if (buttons & Qt::ExtraButton17) returnText += "ExtraButton17 ";
|
|
||||||
if (buttons & Qt::ExtraButton18) returnText += "ExtraButton18 ";
|
|
||||||
if (buttons & Qt::ExtraButton19) returnText += "ExtraButton19 ";
|
|
||||||
if (buttons & Qt::ExtraButton20) returnText += "ExtraButton20 ";
|
|
||||||
if (buttons & Qt::ExtraButton21) returnText += "ExtraButton21 ";
|
|
||||||
if (buttons & Qt::ExtraButton22) returnText += "ExtraButton22 ";
|
|
||||||
if (buttons & Qt::ExtraButton23) returnText += "ExtraButton23 ";
|
|
||||||
if (buttons & Qt::ExtraButton24) returnText += "ExtraButton24 ";
|
|
||||||
return returnText;
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// Copyright (C) 2016 Rick Stockton <rickstockton@reno-computerhelp.com>
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
||||||
#ifndef BUTTONTESTER_H
|
|
||||||
#define BUTTONTESTER_H
|
|
||||||
|
|
||||||
#include <QTextEdit>
|
|
||||||
#include <QString>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QWheelEvent>
|
|
||||||
|
|
||||||
class ButtonTester : public QTextEdit
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
using QTextEdit::QTextEdit;
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
||||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
||||||
#if QT_CONFIG(wheelevent)
|
|
||||||
void wheelEvent(QWheelEvent *event) override;
|
|
||||||
#endif
|
|
||||||
int buttonByNumber(const Qt::MouseButton button);
|
|
||||||
QString enumNameFromValue(const Qt::MouseButton button);
|
|
||||||
QString enumNamesFromMouseButtons(const Qt::MouseButtons buttons);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // BUTTONTESTER_H
|
|
@ -1,36 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// Copyright (C) 2016 Rick Stockton <rickstockton@reno-computerhelp.com>
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
||||||
|
|
||||||
#include "buttontester.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
int main(int argv, char **args)
|
|
||||||
{
|
|
||||||
QApplication app(argv, args);
|
|
||||||
|
|
||||||
ButtonTester *testArea = new ButtonTester;
|
|
||||||
testArea->setMinimumSize(500, 350);
|
|
||||||
|
|
||||||
// For this test, Qt::RightButton behaves like any other button.
|
|
||||||
testArea->setContextMenuPolicy(Qt::NoContextMenu);
|
|
||||||
testArea->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
||||||
testArea->setText("To test your mouse with Qt, press buttons in this area.\nYou may also scroll or tilt your mouse wheel.");
|
|
||||||
QPushButton *quitButton = new QPushButton("Quit");
|
|
||||||
|
|
||||||
QObject::connect(quitButton, &QPushButton::clicked, qApp, &QCoreApplication::quit);
|
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
|
||||||
layout->addWidget(testArea);
|
|
||||||
layout->addWidget(quitButton);
|
|
||||||
|
|
||||||
QWidget window;
|
|
||||||
window.setLayout(layout);
|
|
||||||
window.setWindowTitle("Mouse Button Tester");
|
|
||||||
window.show();
|
|
||||||
|
|
||||||
return app.exec();
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
TEMPLATE = app
|
|
||||||
|
|
||||||
TARGET = mousebuttons
|
|
||||||
TEMPLATE = app
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
main.cpp\
|
|
||||||
buttontester.cpp \
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
buttontester.h \
|
|
||||||
|
|
||||||
# install
|
|
||||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/mousebuttons
|
|
||||||
INSTALLS += target
|
|
||||||
QT += core widgets
|
|
@ -11,7 +11,6 @@ SUBDIRS = analogclock \
|
|||||||
imageviewer \
|
imageviewer \
|
||||||
lineedits \
|
lineedits \
|
||||||
movie \
|
movie \
|
||||||
mousebuttons \
|
|
||||||
scribble \
|
scribble \
|
||||||
shapedclock \
|
shapedclock \
|
||||||
sliders \
|
sliders \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user