2

Can or can't i use PySide.QtGui.QWidget.addAction to place a icon in front of the lineEdit even if this method can take onle one argument in Pyside1?

I want to implement a login UI in my python scripts for 3ds Max, just like How to place an icon onto a QLineEdit? , but i have to use PySide1 because 3ds Max only supports PySide1 before version-2018.

I check Pyside1 and Pyside2 API and i find that:

In PySide1, the method PySide.QtGui.QWidget.addAction(action)can only take 1 arg. this is pyside1 api

But in Pyside2, the same method takes one more arg, like:PySide2.QtWidgets.QLineEdit.addAction(icon, position), which is what i want because i need to place an icon in fornt of the QLineEdit.this is pyside2 api

this is my partly code, self.usernameStr in my class, no error.

# pyside1, which is wrong to take 2 args
# it's in my class
self.usernameStr = QtGui.QLineEdit()
self.usernameStr.addAction("ic_user.svg", QLineEdit().LeadingPosition)

which is wrong, TypeError: addAction() takes exactly one argument (2 given)

But in pyside2, addAction can take the constant LeadingPosition, perfectly like the answer. stackoverflow: how-to-place-an-icon-onto-a-qlineedit

So can or can't i implement this function? Thanks very much for your answer :)

Community
  • 1
  • 1
ltc1996
  • 21
  • 1
  • Sure, you can implement it: just take a look at the [qt5 source](https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlineedit_p.cpp.html#523) and backport all the relevant code to pyside - it should only take a few hours (-; Or if that doesn't appeal to you, why not create a simple custom widget which contains a tool-button and a frameless line-edit (which should only take you twenty minutes or so). – ekhumoro Aug 05 '19 at 10:42

0 Answers0