0

Not able to get this table aligned , it looks very messy.

self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
    self.textBrowser.setGeometry(QtCore.QRect(600, 10, 500,800))
    self.textBrowser.setObjectName("textBrowser")
    self.textBrowser.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
    self.textBrowser.showMaximized()
    self.textBrowser.setFont(QtGui.QFont("Monospace"))
    self.textBrowser.setWordWrapMode(QtGui.QTextOption.NoWrap)
    self.textBrowser.setStyleSheet('color: blue')

enter image description here

chris
  • 4,840
  • 5
  • 35
  • 66
Arvind Sudheer
  • 113
  • 1
  • 1
  • 14
  • 1
    could you include how you are actually putting the data frame into the text browser? also is there any reason you aren't using a QTableView and instead using a text component? – chris Mar 05 '20 at 13:52
  • I've not really explored PyQt a lot and wasn't aware of a QTableView. Anyway, Thanks @chris , I will check that out and also it would be great if you could suggest any documentation (Other than the official one ) related to PyQt which I could refer while doing my project. Thanks again ! – Arvind Sudheer Mar 06 '20 at 05:21
  • Also @chris , for your former question, this is how I'm putting the dataframe in the textbrowser .. 'self.textBrowser.setText(df_new.to_string(col_space =5,justify = "justify"))' – Arvind Sudheer Mar 06 '20 at 05:23

1 Answers1

0

A text widget is not the best way to display data that should be formatted as a table, for which QTableView (or QTableWidget) are more suitable widgets.

If you still want to use a text based widget, you have to set the font to the widget's text document.

    font = QtGui.QFont('Fonospace')
    self.textBrowser.document().setDefaultFont(font)
musicamante
  • 41,230
  • 6
  • 33
  • 58