1 Star 0 Fork 0

linglingier / pyqt6

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
31.py 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
linglingier 提交于 2023-10-17 21:34 . first
# ! /usr/bin/python
# -*- coding: utf-8 -*-
# author:凌
# datetime:2023/10/17 15:54
# software:PyCharm
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QLineEdit
from PyQt6.QtGui import QGuiApplication
class Button(QPushButton):
def __init__(self, title, parent):
super().__init__(title, parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, e):
if e.mimeData().hasFormat("text/plain"):
e.accept()
else:
e.ignore()
def dropEvent(self, e):
self.setText(e.mimeData().text())
class App(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("PyQt6 中的拖拽操作")
edit_text = QLineEdit("", self)
edit_text.setDragEnabled(True)
edit_text.move(30, 65)
button = Button("按钮", self)
button.move(190, 65)
self.setGeometry(100, 100, 400, 300)
self.center()
def center(self):
qr = self.frameGeometry()
cp = QGuiApplication.primaryScreen().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
if __name__ == "__main__":
app = QApplication(sys.argv)
cls_app = App()
cls_app.show()
sys.exit(app.exec())
1
https://gitee.com/lingling2tu/pyqt6.git
git@gitee.com:lingling2tu/pyqt6.git
lingling2tu
pyqt6
pyqt6
master

搜索帮助