3

The user is prompted with a file dialog and chooses a full path which is then put inside a QTableWidgetItem cell within a parent QTableWidget. Currently, when there is an overflow of text in the item and what it can display, it will show the left portion first.

If the full path is C:\Users\JohnDoe\Example_File1.txt it will show: C:\Users\JohnDoe\Ex...

I want the user to be able to see the right portion (the file basename) first before the overflow cutoff occurs such that it will read:

...Doe\Example_File1.txt

I tried implement the following code which changed the alignment but did not appear to work as described above:

    obj = self.QTable1 #A 10x3 table
    for x in range(obj.rowCount()):

        item = obj.item(x,2) #Change alignment for 3rd column (Where paths are stored)
        item.setTextAlignment( QtCore.Qt.AlignRight)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Mets_CS11
  • 99
  • 1
  • 9

1 Answers1

5

You must textElideMode to Qt.ElideLeft and disable wordWrap:

self.QTable1.setTextElideMode(QtCore.Qt.ElideLeft)
self.QTable1.setWordWrap(False)

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thanks for the info, however this does not end up working for my paths column. I actually found an easier method called .setTextElideMode(QtCore.Qt.ElideLeft) which appears to work for the non-path columns. After looking into it, the elide seems to fail when the string is a path. Somehow it detects the slashes and reverts to Elide Right. I'm not sure how to disable this. – Mets_CS11 Apr 01 '20 at 22:01