PyQt5:如何使用布局或几何继承小部件?

时间:2017-11-22 15:41:37

标签: python pyqt5

我在form.ui中放了一个QLineEdit,我想用CustomLabel来继承它。但是我的主窗口中有2个QLineEdit(lines in form.ui和CustomLabel)。

我应该如何处理这种情况?

Here is the image of my programme

这是我的代码:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit, QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
import PyQt5.uic as uic


form_ui,_ =uic.loadUiType('form.ui')
print(type(form_ui))
class Mainwindow(QWidget,form_ui):
    """docstring for App"""
    def __init__(self):
        super(Mainwindow, self).__init__()
        self.setupUi(self)

        path_lineEdit = CustomLabel(self.lines)

class CustomLabel(QLineEdit):

    def __init__(self,parent=None):
        super(CustomLabel,self).__init__(parent)
        # self.resize(parent.size())

    def dragEnterEvent(self, e):
        if e.mimeData().hasFormat('text/plain'):
            e.accept()
        else:
            e.ignore()

    def dropEvent(self, e):
        self.setText('212'+e.mimeData().text())


if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Mainwindow()
    ex.show()
    sys.exit(app.exec_())

0 个答案:

没有答案