QTableView() Align Headers Left - How to?
-
Hello,
I tried with setHeaderData, I tried with CSS QHeaderView::section { nothing works.Question:
How can I left-align column headers? -
Hello,
I tried with setHeaderData, I tried with CSS QHeaderView::section { nothing works.Question:
How can I left-align column headers? -
Thank you.
I import this:from PyQt6.QtCore import Qt
now I get this errormessage:
File "D:\Projekte\Python\qtadressverw_datenbanken\main.py", line 35, in init
self.tabellengrid.horizontalHeader().setDefaultAlignment(Qt.AlignLeft)
AttributeError: type object 'Qt' has no attribute 'AlignLeft'Question:
What I have done wrong? -
I have the solution:
self.tabellengrid.horizontalHeader().setDefaultAlignment(Qt.AlignmentFlag.AlignLeft)
My problem is often that there are a lot of examples for PyQt5 on the web, but that a lot has changed with PyQt6.
thank you for your help!
-
I have the solution:
self.tabellengrid.horizontalHeader().setDefaultAlignment(Qt.AlignmentFlag.AlignLeft)
My problem is often that there are a lot of examples for PyQt5 on the web, but that a lot has changed with PyQt6.
thank you for your help!
@PythonQTMarlem said in QTableView() Align Headers Left - How to?:
My problem is often that there are a lot of examples for PyQt5 on the web, but that a lot has changed with PyQt6.
I'm afraid that's just how it is!
We recently had a similar issue where they have now changed to insert the "enumeration type name" before the enumeration value. And they have not updated the PySide documentation to mention this. See https://forum.qt.io/topic/139109/seteditstrategy-attributeerror-type-object-qsqltablemodel-has-no-attribute-onfieldchange/4, where @SGaist correctly guessed they had changed
QSqlTableModel.OnFieldChange
over toQSqlTableModel.EditStrategy.OnFieldChange
. Oh, that was you too! So it looks like if you are using an enumerated type and you get a Python AttributeError that is the first thing to think of.Hey, I just found PyQtEnumConverter 1.0
PyQt6 changes the usage of enums. Here are some examples:
To change all of this is a lot of work when you port a big project from PyQt5 to PyQt6. To help porting I had written this little script that does the work for youYou could use that, or just look at/search its source code when you have a enumerated value to see what it has been changed over to.
Also read https://www.pythonguis.com/faq/pyqt5-vs-pyqt6/
The change mostly likely to impact your projects is the removal of the short-form names for enum members. In PyQt6 all enum members must be named using their fully qualified names.
-
Thanks for your detailed answer and the link.