I want to edit lineEdit
from an .ui
file which is imported. I would not like to convert .ui
to .py
code because .ui
will be changed frequently and converting to .py and import from the .py seems a longer proccess for me.
When run the code, It seems that instead of one, two seperate lineEdit
is generated in mainwindow. Probably parent-subclass relationships due to formclass ui
but I could not understand why?
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import sys,re
import pandas as pd
from glob import glob
import os
ui,base=uic.loadUiType("test.ui")
class MainWindow(ui,base):
def __init__(self, parent=None):
base.__init__(self,parent)
# initializes the user interface
self.setupUi(self)
self.lineEdit=lineEdit(self.lineEdit)
class lineEdit(QtWidgets.QLineEdit):
def __init__(self, parent):
super().__init__(parent)
self.parent=parent
self.setAcceptDrops(True)
self.setDragEnabled(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.acceptProposedAction()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.acceptProposedAction()
else:
event.ignore()
def dropEvent(self, event):
mymodel=QtGui.QStandardItemModel()
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
for url in event.mimeData().urls():
links=url.toLocalFile()
self.setText(links)
return links
if __name__ == "__main__":
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
MainWindow=MainWindow()
MainWindow.show()
app.exec_()
Changed self.lineEdit=lineEdit(self)
resulted two seperate lineEdit
while self.lineEdit=lineEdit(self.lineEdit)
cause two coincident lineEdit
widget at the same coordinates of mainwindow.
Any help would be nice...
Edit:test.ui is here https://drive.google.com/open?id=1oe6z2BaiLYm0mo-nadmDvzsoLHXnwkfm