Sep-06-2019, 01:10 PM
The below code is showing lineEdit such that when a text is written, it showed the text not throughout of the width of the lineEdit. Kind of seemed like it is divided by half.
Based on my try and errors, the cause is
Any Help would be great
Thnks :)
Based on my try and errors, the cause is
self.lineEdit=lineEdit(ui.lineEdit)to initialize the mainwindow.
Any Help would be great
Thnks :)
from PyQt5 import QtCore, QtGui, QtWidgets, uic import sys,re import pandas as pd from glob import glob import os class MainWindow(QtWidgets.QMainWindow): def __init__(self, parent=None): super().__init__(parent) ui=uic.loadUi('simple.ui',self) # initializes the user interface self.lineEdit=lineEdit(ui.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 mimeTypes(self): # mimeTypes=super().mimeTypes() # mimeTypes.append("text/plain") # return mimeTypes 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_()