Python Forum
[PyQt] Why lineEdit is showing text like this ??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Why lineEdit is showing text like this ??
#1
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
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_() 
Reply


Messages In This Thread
Why lineEdit is showing text like this ?? - by scorp08 - Sep-06-2019, 01:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] Showing text in QTableView sequence 0 3,081 Jan-20-2019, 05:00 PM
Last Post: sequence
  [PyQt] Need Help about comboBox and lineEdit DeanONeil 1 2,699 Oct-13-2017, 05:42 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020