• pyQt5练习(二)


    屏幕坐标系:

      屏幕左上角坐标是(0,0)

      工作区高度:窗口高度(不包括标签栏)

      标签栏高度:标签栏坐标减去工作区坐标

      widget.resize(300,240) 设置的是工作区的尺寸

    import sys
    from PyQt5.QtWidgets import QPushButton,QHBoxLayout,QWidget,QApplication, QMainWindow,QDesktopWidget
    from PyQt5.QtGui import QIcon
    #此例子中使用面向过程的方式,不使用类了
    def onClick_Button():
        print("含边框的坐标")
        print("widget.x()= %d" % widget.x())        #含有边框的坐标    250(窗口横坐标)
        print("widget.y()= %d" % widget.y())        #200(窗口纵坐标)
        print("widget.width()= %d" % widget.width()) #300(工作区宽度)
        print("widget.height() = %d" % widget.height())#240(工作区高度)
     
        print("工作区的坐标")
        print("widget.geometry().x()= %d" % widget.geometry().x()) #工作区的坐标系,不包含标题栏 251(工作区横坐标)
        print("widget.geometry().y()= %d" % widget.geometry().y())          #231(工作区纵坐标)
        print("widget.geometry().width()= %d" % widget.geometry().width())  #300(工作区宽度)
        print("widget.geometry().height() = %d" % widget.geometry().height())#240(工作区高度)
     
        print("框架的坐标")
        print("widget.frameGeometry().x()= %d" % widget.frameGeometry().x())    #250(窗口横坐标)
        print("widget.frameGeometry().y()= %d" % widget.frameGeometry().y())    #200(窗口纵坐标)
        print("widget.frameGeometry().width()= %d" % widget.frameGeometry().width()) #302(窗口宽度)
        print("widget.frameGeometry().height() = %d" % widget.frameGeometry().height()) #272(窗口高度 =标题栏高度+工作区高度)
    app = QApplication(sys.argv)
    widget = QWidget()
    btn = QPushButton(widget)
    btn.setText("按钮")
    btn.clicked.connect(onClick_Button)
    btn.move(24,52)
    widget.resize(300,240)  #设置工作区的尺寸
    widget.move(250,200)
    widget.setWindowTitle("屏幕坐标系")
    widget.show()
    sys.exit(app.exec_())
     
     

    设置窗口图标:

    def initUI(self):
    self.setGeometry(300,300,250,250)
    # 设置主窗口的标题
    self.setWindowTitle("设置窗口图标")
    #设置窗口图标
    self.setWindowIcon(QIcon('./images/t10.ico'))

  • 相关阅读:
    基本配置+路由系统+模板
    ORM之SQLAlchemy
    web应用+250斗笔式模拟框架(socket、pymysql、jinja2)
    Leetcode56. Merge Intervals合并区间
    Leetcode50. Pow(x, n)(快速幂)
    Leetcode43. Multiply Strings字符串相乘(大数相乘)
    (转)Json在Unity中的简单使用
    Leetcode49. Group Anagrams字母异位词分组
    Leetcode48. Rotate Image旋转图像
    Leetcode47. Permutations II全排列2
  • 原文地址:https://www.cnblogs.com/tianwenjing123-456/p/14941564.html
Copyright © 2020-2023  润新知