Ejemplo n.º 1
0
def mouse_click_qwidget(control, delay):
    """Performs a mouce click on a Qt widget.

    Parameters
    ----------
    control : Qwidget
        The Qt widget to be clicked.
    delay : int
        Time delay (in ms) in which click will be performed.
    """

    # for QAbstractButtons we do not use QTest.mouseClick as it assumes the
    # center of the widget as the location to be clicked, which may be
    # incorrect. For QAbstractButtons we can simply call their click method.
    if isinstance(control, QtGui.QAbstractButton):
        if delay > 0:
            QTest.qSleep(delay)
        control.click()
    elif control is not None:
        QTest.mouseClick(
            control,
            QtCore.Qt.MouseButton.LeftButton,
            delay=delay,
        )
    else:
        raise ValueError("control is None")