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. Text alignment in QTableWidget object

Text alignment in QTableWidget object

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 3.8k 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.
  • A Offline
    A Offline
    Achab61
    wrote on 11 Feb 2022, 16:27 last edited by
    #1

    Hi all,

    I'm a beginner in Python QT and I'm struggling with an apparent simple problem: I would need to align the text of an item loaded from a MySQL table into a QTableWidget object. I searched the web but I couldn't find any solution.

    Can you help me ?
    Thanks in advance

    J 1 Reply Last reply 11 Feb 2022, 16:39
    0
    • A Achab61
      11 Feb 2022, 16:27

      Hi all,

      I'm a beginner in Python QT and I'm struggling with an apparent simple problem: I would need to align the text of an item loaded from a MySQL table into a QTableWidget object. I searched the web but I couldn't find any solution.

      Can you help me ?
      Thanks in advance

      J Offline
      J Offline
      JonB
      wrote on 11 Feb 2022, 16:39 last edited by JonB 2 Nov 2022, 16:39
      #2

      @Achab61
      A QTableWidget's items are QTableWidgetItems. And that has QTableWidgetItem::setTextAlignment().

      Having said that, QTableWidget is not the optimal widget to show data from SQL database tables, because it has its own model, you will be copying things between the SQL data model and the QTableWidget. At some stage you might want to consider moving to a QTableView which can display data from the SQL model.

      A 2 Replies Last reply 11 Feb 2022, 21:33
      1
      • J JonB
        11 Feb 2022, 16:39

        @Achab61
        A QTableWidget's items are QTableWidgetItems. And that has QTableWidgetItem::setTextAlignment().

        Having said that, QTableWidget is not the optimal widget to show data from SQL database tables, because it has its own model, you will be copying things between the SQL data model and the QTableWidget. At some stage you might want to consider moving to a QTableView which can display data from the SQL model.

        A Offline
        A Offline
        Achab61
        wrote on 11 Feb 2022, 21:33 last edited by
        #3

        @JonB Thanks a lot!

        1 Reply Last reply
        0
        • J JonB
          11 Feb 2022, 16:39

          @Achab61
          A QTableWidget's items are QTableWidgetItems. And that has QTableWidgetItem::setTextAlignment().

          Having said that, QTableWidget is not the optimal widget to show data from SQL database tables, because it has its own model, you will be copying things between the SQL data model and the QTableWidget. At some stage you might want to consider moving to a QTableView which can display data from the SQL model.

          A Offline
          A Offline
          Achab61
          wrote on 12 Feb 2022, 17:03 last edited by
          #4

          @JonB Would you mind provide with an example about how it looks like the statement for the setTextAlignment in Python ?

          J 1 Reply Last reply 12 Feb 2022, 17:27
          0
          • A Achab61
            12 Feb 2022, 17:03

            @JonB Would you mind provide with an example about how it looks like the statement for the setTextAlignment in Python ?

            J Offline
            J Offline
            JonB
            wrote on 12 Feb 2022, 17:27 last edited by
            #5

            @Achab61
            https://stackoverflow.com/questions/46772790/pyside-align-text-in-a-table-cells

            1 Reply Last reply
            0

            1/5

            11 Feb 2022, 16:27

            • Login

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