zoukankan      html  css  js  c++  java
  • PyQt5--TextDrag

     1 # -*- coding:utf-8 -*-
     2 '''
     3 Created on Sep 21, 2018
     4 
     5 @author: SaShuangYiBing
     6 
     7 Comment: 
     8 '''
     9 import sys
    10 from PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QLineEdit
    11 
    12 class Button(QPushButton):
    13     def __init__(self,title,parent):
    14         super().__init__(title,parent)
    15         self.setAcceptDrops(True)
    16         
    17     def dragEnterEvent(self,e):
    18         if e.mimeData().hasFormat('text/Plain'):
    19             e.accept()
    20         else:
    21             e.ignore()
    22     
    23     def dropEvent(self,e):
    24         self.setText(e.mimeData().text())
    25 
    26 class New_test(QWidget):
    27     def __init__(self):
    28         super().__init__()
    29         self.initUI()
    30         
    31     def initUI(self):
    32         edit = QLineEdit('',self)
    33         edit.setDragEnabled(True)
    34         edit.move(30,65)
    35         
    36         button = Button('Button',self)
    37         button.move(190,65)
    38         
    39         self.setWindowTitle('Simple drag & drop')
    40         self.setGeometry(300,300,300,150)
    41         self.show()
    42         
    43 if __name__ == '__main__':
    44     app = QApplication(sys.argv)
    45     ex = New_test()
    46     sys.exit(app.exec_())
    47         

    在文本框中输入的内容,随意选中其中部分字符可进行拖拽(类似复制)

  • 相关阅读:
    模拟赛QAQ
    复习计划
    luogu P1080 国王游戏
    [NOIP2012T3]开车旅行
    luogu P1967 货车运输
    同余方程组的扩展欧几里得解法
    luogu P1476 休息中的小呆
    GRYZY #13. 拼不出的数
    GRYZY- #10. 财富
    GRYZY #8. 公交车
  • 原文地址:https://www.cnblogs.com/aziji/p/9685186.html
Copyright © 2011-2022 走看看