PyQt: 获取指定坐标的控件PyQt: 获取指定坐标的控件PyQt: 获取指定坐标的控件PyQt: 获取指定坐标的控件
  • 首页
  • 博客
  • 文件
  • 书签
  • 分析
  • 登录
Search
Generic filters

PyQt: 获取指定坐标的控件

Published by admin at 2022年3月29日
Categories
  • Practice
Tags
import sys
import time

from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.set_ui()

    def set_ui(self):
        self.resize(300, 300)
        self.setWindowTitle("主窗口")
        self.setObjectName("0")
        self.custom_label()
        self.show()

    def mousePressEvent(self, a0) -> None:
        # 标签不处理鼠标点击事件,事件传递至父对象,由父对象处理
        # 点击区域如有子控件
        if self.childAt(a0.x(), a0.y()) is not None:
            self.childAt(a0.x(), a0.y()).setStyleSheet("background-color:red")

    def custom_label(self):
        for i in range(10):
            self.label_1 = QLabel(self)
            self.label_1.move(20 * i + 20, 20 * i + 20)
            self.label_1.setText("标签" + str(i))
            self.label_1.setStyleSheet("background-color:green")
            self.label_1.setObjectName("label" + str(i))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    sys.exit(app.exec_())

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Categories

  • 猫
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2022 Alaica Blog support@alaica.com