Issue
I have long text items in QComboBox
, and I want to display complete text of items in multiple lines. What should I do. Thank you. Currently it puts ...
between the start and end of text.
Solution
To get something like on the image:
I'll need QListView (with its method setWordWrap), QStringListModel (for example only, you can use any model) and QComboBox.
Example:
import sys
from PyQt5.QtWidget import QComboBox, QListView, QApplication
from PyQt5.QtCore import QStringListModel
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
combo = QComboBox()
combo.setMaximumWidth(150)
# For the popup items data we use QStringListModel
combo.setModel(QStringListModel([
'1. Lo',
'2. Lorem',
'3. Lorem ipsum dolor sit amet, consectetur',
'4. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut',
'5. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco labor'
]))
# The popup widget is QListView
listView = QListView()
# Turn On the word wrap
listView.setWordWrap(True)
# set popup view widget into the combo box
combo.setView(listView)
combo.show()
sys.exit(app.exec_())
Answered By - Alexander Chernin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.