Results 1 to 6 of 6

Thread: PyQt5 - Fail to display QTableWidgetItem data if previous cell have same value?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default PyQt5 - Fail to display QTableWidgetItem data if previous cell have same value?

    Hm, I just stumbled into an issue that I don't know how to address. Somehow my QtableWidget won't show the data of 2 specific columns if the data on both is the same.
    Please check the next screenshot to see what I meant. There shouldn't be invisible values on the 2nd column at all.
    b4MAz8NLRCe7lk3jtxfMSA.png
    The first row values I doublechecked multiple times and it's "No No", but it only shows first one.
    Also doublechecked the 3rd row, the value there is "SÃ* SÃ*", but yet again second one is invisible.
    This is the big picture in case you need to check:
    M4FvuArqQWic7bBzBLGi-Q.jpg

    I fail to see why this happens.

    Qt Creator pyuic5 generated code:
    Qt Code:
    1. self.tablaBuscador = QtWidgets.QTableWidget(self.tab_buscador)
    2. self.tablaBuscador.setGeometry(QtCore.QRect(10, 40, 941, 341))
    3. self.tablaBuscador.setStyleSheet("")
    4. self.tablaBuscador.setColumnCount(0)
    5. self.tablaBuscador.setObjectName("tablaBuscador")
    6. self.tablaBuscador.setRowCount(0)
    7. self.tablaBuscador.verticalHeader().setDefaultSectionSize(25)
    8. self.tablaBuscador.setSortingEnabled(True)
    To copy to clipboard, switch view to plain text mode 

    This is the code where I create the table columns and headers:
    Qt Code:
    1. def creatabla_buscador(self):
    2. # Add columns and give them a header name
    3. nombres_de_columnas = ["Fecha Entrada", "Proveedor", "Fecha Factura", "Importe",
    4. "Cód. Factura", "Pagada", "Contabilizada", "Observaciones"]
    5. self.tablaBuscador.setColumnCount(len(nombres_de_columnas))
    6. self.tablaBuscador.setHorizontalHeaderLabels(nombres_de_columnas)
    7. # Adjust the size to fit perfectly
    8. header = self.tablaBuscador.horizontalHeader()
    9. for i in nombres_de_columnas:
    10. if i == "Observaciones":
    11. header.setSectionResizeMode(nombres_de_columnas.index(i), QtWidgets.QHeaderView.Stretch)
    12. else:
    13. header.setSectionResizeMode(nombres_de_columnas.index(i), QtWidgets.QHeaderView.ResizeToContents)
    14. # Connect what happens when you click on any cell
    15. self.tablaBuscador.cellClicked.connect(self.tablabuscador_alclickearceldas)
    To copy to clipboard, switch view to plain text mode 

    And this is the code I use to create rows filled with data requested from Sqlite3
    Qt Code:
    1. def rellenatabla_buscador(self):
    2. # Destroy all table data in order to replace it
    3. self.tablaBuscador.setRowCount(0)
    4. # Find the information
    5. registros = utilidades_db.buscatodoslosregistros("Recibos",
    6. "SELECT Fechaentrada, Proveedor, Fechafactura, "
    7. "Importefactura, Codigofacturadelproveedor, Pagada, "
    8. "Contabilizar, Observaciones FROM FacturasRecibidas "
    9. "WHERE Proveedor LIKE ?",
    10. (self.comboBuscador_proveedor.currentText(),), True)
    11. # Order them by index 0
    12. registros = utilidades.ordena_registros_por(registros, 0)
    13. # Create the new rows and add the items
    14. for registro in registros:
    15. self.tablaBuscador.insertRow(self.tablaBuscador.rowCount())
    16. fila = self.tablaBuscador.rowCount() - 1
    17. for dato in registro:
    18. registroitem = QtWidgets.QTableWidgetItem(utilidades.ensure_its_str(dato))
    19. registroitem.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
    20. registroitem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
    21. self.tablaBuscador.setItem(fila, registro.index(dato), registroitem)
    To copy to clipboard, switch view to plain text mode 

    And I fire them together upon selecting a value on the QComboBox above it, no weird stuff in between:
    Qt Code:
    1. self.creatabla_buscador()
    2. self.rellenatabla_buscador()
    To copy to clipboard, switch view to plain text mode 

    Notes:
    Explaining possibly confusing functions.
    ensure_its_str = It just check if the data proved is a string. If not, it converts that data as a string: str(data)
    buscatodoslosregistros = Just a wrapper for "connect to database, use cursors, disconnect to database".
    ordena_registros_por = It just re-order the list of items on an specific index.
    Last edited by Saelyth; 16th August 2017 at 19:12.

Similar Threads

  1. Replies: 14
    Last Post: 18th June 2017, 17:32
  2. Replies: 13
    Last Post: 17th July 2016, 16:20
  3. Qt for Symbian clear previous data when replace app ?
    By Dexter in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 03:25
  4. How do I display a picture on a QTableView cell?
    By danielperaza in forum Qt Programming
    Replies: 16
    Last Post: 9th April 2010, 22:04
  5. Replies: 2
    Last Post: 29th March 2010, 11:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.