QApplication.widgetAt()函数详细教程


Pyside6.QtWidgets.QApplication类的成员函数widgetAt()用于返回屏幕位置(x,y)处的小部件对象,如果那里没有Qt小部件,则返回None;该方法无法获取其它进程的Qt小部件;

示例代码

import sys
from PySide6.QtWidgets import QApplication,QWidget,QPushButton,QVBoxLayout
from PySide6.QtCore import Slot

class MyWidget(QWidget):
    def __init__(self):
        super().__init__()

        self.button = QPushButton("使用widgetAt()")
        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.button)
        self.button.clicked.connect(self.getWidget)

    @Slot()
    def getWidget(self):
        print(app.widgetAt(50,50)) #获取屏幕位置50,50处的Qt小部件

app = QApplication([])

widget = MyWidget()
widget.resize(300, 200)
widget.show()
sys.exit(app.exec())

该代码将获得屏幕上50,50处的Qt小部件对象;

如需转载,请注明出处;本文地址:https://www.perfcode.com/p/pyside6-qtwidgets-qapplication-widgetat.html