The interfaces can imitate users’ operations.

QTest::keyClick
QTest::keyPress
QTest::mouseClick

QSignalSpy listens for signal emission, it is a list of QVariant lists.
It will not shield off signal to make slot invalid.

  QCheckBox *box = ...;
  QSignalSpy spy(box, SIGNAL(clicked(bool)));
//...
  QList arguments = spy.takeFirst(); // take the first signal
  QVERIFY(arguments.at(0).toBool() == true); // verify the first argument

We can use installEventFilter to make mouse left button, right button, and middle button press invalid.
Example code:

class MousePressEater : public QObject
{
    Q_OBJECT
public:
    explicit MousePressEater(QObject *parent = nullptr);
protected:
    bool eventFilter(QObject *obj, QEvent *event) override;
};

bool MousePressEater::eventFilter(QObject *obj, QEvent *event)

{

    if (event->type() == QEvent::MouseButtonRelease) {

        QMouseEvent *mouseEvent = static_cast(event);

        qDebug("mouseEvent press %d", mouseEvent->button());

        return true;

    } else {

        // standard event processing

        return QObject::eventFilter(obj, event);

    }

}

//...

    pressEater = new MousePressEater (this);

    ui->pushButton->installEventFilter( pressEater );

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x