Property with a list as possible values for custom widget?
-
I use QtGui.QListWidget (the Qt Designer 's QListWidget )
ContainersWidgets = QtCore.pyqtProperty(QtGui.QListWidget, getContainersWidgets, setContainersWidgets)
But how do I set the value?
@QtCore.pyqtSlot(int) def setContainersWidgets(self, value): self._containers_widgets = value
So the variable self._containers_widgets will get the value.
How shall I put this value as selected item from the list?First of all, how shall I refer to the list?(I mean the widget, the QtGui.QListWidget)
list=?? -
I use QtGui.QListWidget (the Qt Designer 's QListWidget )
ContainersWidgets = QtCore.pyqtProperty(QtGui.QListWidget, getContainersWidgets, setContainersWidgets)
But how do I set the value?
@QtCore.pyqtSlot(int) def setContainersWidgets(self, value): self._containers_widgets = value
So the variable self._containers_widgets will get the value.
How shall I put this value as selected item from the list?First of all, how shall I refer to the list?(I mean the widget, the QtGui.QListWidget)
list=??Hi
Sadly I dont know enough python to know.http://pyqt.sourceforge.net/Docs/PyQt4/qstringlist.html#details
-
Don't worry my friend, 'll find out the way, sooner or later.
I 'm not sure it is correct that I 'm using Qt Designer 's QListWidget in the place of 'QList<int>' you wrote above.
Or maybe I should use QStringList?
The QList you 're referring to, is a widget?I think I should use QStringList in place of your QList.
-
Don't worry my friend, 'll find out the way, sooner or later.
I 'm not sure it is correct that I 'm using Qt Designer 's QListWidget in the place of 'QList<int>' you wrote above.
Or maybe I should use QStringList?
The QList you 're referring to, is a widget?I think I should use QStringList in place of your QList.
Hi
QListWidget is a widget ( listbox) so that is not well for properties.- I think I should use QStringList in place of your QList.
I agree since QList is template based it might be missing as QList.
But QStringList is
class QStringList : public QList<QString>
So very alike.
Maybe this can be used
http://www.programcreek.com/python/example/63681/PyQt4.QtCore.QStringList - I think I should use QStringList in place of your QList.
-
From here:
From PyQt4 4.6+ in Python3 QString doesn't exist and you are supposed to use ordinary Python3 unicode objects (string literals). To do this so that your code will work in both Python 2.x AND Python 3.x you can do following:
try: from PyQt4.QtCore import QString except ImportError: # we are using Python3 so QString is not defined QString = type("")
Ok, this for QString.
From here:
The QList class is a template class that provides lists. available in C++ only. But in python, it have python list data-type ready to used. If you want to use behavior like list you can use python list similar QListSo how will I do it? QList = []?
(with '[]' we define a list in python)
-
I tried this:
QList = []
ContainersWidgets = QtCore.pyqtProperty(QList, getContainersWidgets, setContainersWidgets)
But I get an error:
"ContainersWidgets = QtCore.pyqtProperty(QList, getContainersWidgets, setContainersWidgets)
TypeError: bytes or ASCII string expected not 'list'"It doesn't accept a List, only bytes or ASCII.
-
I tried this:
QList = []
ContainersWidgets = QtCore.pyqtProperty(QList, getContainersWidgets, setContainersWidgets)
But I get an error:
"ContainersWidgets = QtCore.pyqtProperty(QList, getContainersWidgets, setContainersWidgets)
TypeError: bytes or ASCII string expected not 'list'"It doesn't accept a List, only bytes or ASCII.
I think you need a python head for this :)
Are you using
https://pypi.python.org/pypi/PyQt5or what version ?
-
@Panoss said in Property with a list as possible values for custom widget?:
PyQt4
ok it really should have the qstringlist
-
https://hub.qgis.org/wiki/17/Python_plugin_API_changes_from_18_to_20#Replace-QStringList-with-list
"Replace QList methods with python list function"
So both Qlist and QStringList are replaced by list.
-
https://hub.qgis.org/wiki/17/Python_plugin_API_changes_from_18_to_20#Replace-QStringList-with-list
"Replace QList methods with python list function"
So both Qlist and QStringList are replaced by list.
But is that no QGIS API ?
is that the same as
https://sourceforge.net/projects/pyqt/It looks as some other binding. So i Guess that is why its not there.
-
I tried this:
QList = []
ContainersWidgets = QtCore.pyqtProperty(QList, getContainersWidgets, setContainersWidgets)
But I get an error:
"ContainersWidgets = QtCore.pyqtProperty(QList, getContainersWidgets, setContainersWidgets)
TypeError: bytes or ASCII string expected not 'list'"It doesn't accept a List, only bytes or ASCII.
@Panoss said in Property with a list as possible values for custom widget?:
QList = []
Should be
QList = type([])
-
@Panoss said in Property with a list as possible values for custom widget?:
QList = []
Should be
QList = type([])
@jsulm said in Property with a list as possible values for custom widget?:
@Panoss said in Property with a list as possible values for custom widget?:
QList = []
Should be
QList = type([])
You re right!!!
Now the error is gone!But my property doesn't appear in Qt Designer.