Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QTableView() Align Headers Left - How to?

QTableView() Align Headers Left - How to?

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PythonQTMarlem
    wrote on last edited by
    #1

    Hello,
    I tried with setHeaderData, I tried with CSS QHeaderView::section { nothing works.

    Question:
    How can I left-align column headers?

    jsulmJ 1 Reply Last reply
    0
    • P PythonQTMarlem

      Hello,
      I tried with setHeaderData, I tried with CSS QHeaderView::section { nothing works.

      Question:
      How can I left-align column headers?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @PythonQTMarlem What about https://doc.qt.io/qt-6/qheaderview.html#defaultAlignment-prop ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PythonQTMarlem
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PythonQTMarlem
          wrote on last edited by
          #4

          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!

          JonBJ 1 Reply Last reply
          1
          • P PythonQTMarlem

            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!

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @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 to QSqlTableModel.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 you

            You 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.

            1 Reply Last reply
            1
            • P Offline
              P Offline
              PythonQTMarlem
              wrote on last edited by
              #6

              Thanks for your detailed answer and the link.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved