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
Forum Updated to NodeBB v4.3 + New Features

Text alignment in QTableWidget object

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 4.0k 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 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

    JonBJ 1 Reply Last reply
    0
    • A Achab61

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #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
      1
      • JonBJ JonB

        @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 last edited by
        #3

        @JonB Thanks a lot!

        1 Reply Last reply
        0
        • JonBJ JonB

          @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 last edited by
          #4

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

          JonBJ 1 Reply Last reply
          0
          • A Achab61

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

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

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

            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