0

Basically, I have text in a table that I would like to be displayed as a list in my GUI application.

What I have:

column1    | column2    | column3   |

-----------| -----------| ----------|

col1atext  | col2atext  | col3atext |

col1btext  | col2btext  | col3btext |

What I need:

col1atext    #wrap to the next line  

col2atext    #wrap to the next line

col3atext      

------------

col1btext    #wrap to the next line

col2btext    #wrap to the next line

col3btext      

------------

I have exhausted my Google search, and have not found any examples of this. Everything I see allows for just one line of text in a list, but I'd like to show a list of lists (multiple lines of text). I could just create a single string of text with enough spaces between the separate pieces of text in order to force text wrapping over several lines, but that doesn't seem like a real solution (pseudocode below).

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import PCA_mod2ui #UI design file

class PCAmod2App(QtWidgets.QMainWindow, PCA_mod2ui.Ui_MainWindow):
    def __init__(self, parent=None):
        super(PCAmod2App, self).__init__(parent)
        self.setupUi(self)
        ## below defined in PCA_mod2ui, converted from QT Designer
        """
        self.projectListWidget = QtWidgets.QListWidget(self.centralwidget)
        self.projectListWidget.setGeometry(QtCore.QRect(20, 10, 311, 531))
        self.projectListWidget.setLineWidth(1)
                self.projectListWidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.projectListWidget.setAlternatingRowColors(True)
            self.projectListWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
            self.projectListWidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerItem)
        self.projectListWidget.setProperty("isWrapping", True)
        self.projectListWidget.setWordWrap(True)
        self.projectListWidget.setSelectionRectVisible(True)
        self.projectListWidget.setObjectName("projectListWidget")
        """
        dpspace = ' '
        spacer =95

        datapoint1a='text1'
        datapoint1b='text2'
        datapoint1c='text3'
        d1aspace = dpspace*(spacer-len(datapoint1a))
        d1bspace = dpspace*(spacer-len(datapoint1b))
        datapoint1 =datapoint1a+d1aspace+datapoint1b+d1bspace+datapoint1c

        datapoint2a='2'+datapoint1a
        datapoint2b='2'+datapoint1b
        datapoint2c='2'+datapoint1c
        d2aspace = dpspace*(spacer-len(datapoint2a))
        d2bspace = dpspace*(spacer-len(datapoint2b))
        datapoint2 =datapoint2a+d2aspace+datapoint2b+d2bspace+datapoint2c

        datalist=[datapoint1,datapoint2]

        self.projectListWidget.addItems(datalist)

def main():
    app = QtWidgets.QApplication(sys.argv)
    form = PCAmod2App()
    form.show() #show the form
    app.exec_() #execute the app

if __name__ == '__main__':
    main()

Any ideas to make this better?

Update 4/10/17: found a solution from this question.

Community
  • 1
  • 1
Nicole
  • 1
  • 1

0 Answers0