Results 1 to 2 of 2

Thread: Pyhon 3 - PyQT4: Table model

  1. #1
    Join Date
    Mar 2012
    Location
    Argentine
    Posts
    2
    Qt products
    Platforms
    Windows

    Question Pyhon 3 - PyQT4: Table model

    Hi im new in Python and Qt

    I have some questions and problems.


    1- How can NoEdit for one column my case the id column?


    Qt Code:
    1. def ejecutar_query_ver_items(self):
    2. self.ventana.data_base.open()
    3. winsound.PlaySound("SystemAsterisk", winsound.SND_ASYNC)
    4. self.ventana.var_select_model.setTable('items')
    5. self.ventana.var_select_model.select()
    6. self.ventana.var_select_model.setHeaderData(0, QtCore.Qt.Horizontal, "ID")
    7. self.ventana.var_select_model.setHeaderData(1, QtCore.Qt.Horizontal, "Nombre")
    8. self.ventana.var_select_model.setHeaderData(2, QtCore.Qt.Horizontal, "Cantidad")
    9. self.ventana.var_select_model.setHeaderData(3, QtCore.Qt.Horizontal, "Precio")
    10. self.ventana.var_select_model.setHeaderData(4, QtCore.Qt.Horizontal, "Ultima Modificacion")
    11. self.ventana.var_select_model.setHeaderData(5, QtCore.Qt.Horizontal, "IP")
    12. self.ventana.tableView_ver_items.setModel(self.ventana.var_select_model)
    13. self.ventana.tableView_ver_items.hideColumn(5)
    14. self.ventana.data_base.close()
    To copy to clipboard, switch view to plain text mode 

    2- If not use "self.ventana.data_base.close()" querys crash when I insert or delete, but with this problem i can´t change the fields in real time.

    Qt Code:
    1. def ejecutar_query_ver_items(self):
    2. self.ventana.data_base.open()
    3. winsound.PlaySound("SystemAsterisk", winsound.SND_ASYNC)
    4. self.ventana.var_select_model.setTable('items')
    5. self.ventana.var_select_model.select()
    6. self.ventana.var_select_model.setHeaderData(0, QtCore.Qt.Horizontal, "ID")
    7. self.ventana.var_select_model.setHeaderData(1, QtCore.Qt.Horizontal, "Nombre")
    8. self.ventana.var_select_model.setHeaderData(2, QtCore.Qt.Horizontal, "Cantidad")
    9. self.ventana.var_select_model.setHeaderData(3, QtCore.Qt.Horizontal, "Precio")
    10. self.ventana.var_select_model.setHeaderData(4, QtCore.Qt.Horizontal, "Ultima Modificacion")
    11. self.ventana.var_select_model.setHeaderData(5, QtCore.Qt.Horizontal, "IP")
    12. self.ventana.tableView_ver_items.setModel(self.ventana.var_select_model)
    13. self.ventana.tableView_ver_items.hideColumn(5)
    14. self.ventana.data_base.close()
    15.  
    16. def ejecutar_query_agregar_items(self):
    17. self.ventana.data_base.open()
    18.  
    19. if self.ventana.lineEdit_nombre_del_item.text() == '' or self.ventana.lineEdit_cantidad_del_item.text() == '' or self.ventana.lineEdit_valor_del_item.text() == '' :
    20. winsound.PlaySound("SystemHand", winsound.SND_ASYNC)
    21. self.ventana.mensaje_alerta_completar_casilla = QtGui.QMessageBox.warning(self, 'Mensaje',
    22. "Debes completar las casillas", QtGui.QMessageBox.Yes)
    23.  
    24. self.ventana.data_base.close()
    25. else:
    26. winsound.PlaySound("SystemQuestion", winsound.SND_ASYNC)
    27. self.ventana.mensaje_alerta_ingresar = QtGui.QMessageBox.question(self, 'Mensaje',
    28. "¿Seguro que quieres agregar el item?", QtGui.QMessageBox.Yes |
    29. QtGui.QMessageBox.No)
    30.  
    31.  
    32. if self.ventana.mensaje_alerta_ingresar == QtGui.QMessageBox.Yes:
    33. winsound.PlaySound("SystemAsterisk", winsound.SND_ASYNC)
    34. self.ventana.var_insert_model.exec("INSERT INTO items (nombre, cantidad, precio, ultima_modificacion, ip_de_quien_agrego) VALUES " + str ( (self.ventana.lineEdit_nombre_del_item.text(),self.ventana.lineEdit_cantidad_del_item.text(),self.ventana.lineEdit_valor_del_item.text(), self.ventana.horario_pc, self.ventana.var_detecto_ip)))
    35. self.ventana.var_select_despues_de_ingresar_model.setTable('items')
    36. self.ventana.var_select_despues_de_ingresar_model.select()
    37. self.ventana.var_select_despues_de_ingresar_model.setHeaderData(0, QtCore.Qt.Horizontal, "ID")
    38. self.ventana.var_select_despues_de_ingresar_model.setHeaderData(1, QtCore.Qt.Horizontal, "Nombre")
    39. self.ventana.var_select_despues_de_ingresar_model.setHeaderData(2, QtCore.Qt.Horizontal, "Cantidad")
    40. self.ventana.var_select_despues_de_ingresar_model.setHeaderData(3, QtCore.Qt.Horizontal, "Precio")
    41. self.ventana.var_select_despues_de_ingresar_model.setHeaderData(4, QtCore.Qt.Horizontal, "Ultima Modificacion")
    42. self.ventana.tableView_ver_items.setModel(self.ventana.var_select_despues_de_ingresar_model)
    43. self.ventana.tableView_ver_items.hideColumn(5)
    44.  
    45. self.ventana.data_base.close()
    46. else:
    47. print('Cancelo')
    48. self.ventana.data_base.close()
    49.  
    50. def ejecutar_query_sacar_items(self):
    51. self.ventana.data_base.open()
    52.  
    53. if self.ventana.lineEdit_id_para_eliminar_items.text() == '' :
    54. winsound.PlaySound("SystemHand", winsound.SND_ASYNC)
    55. self.ventana.mensaje_alerta_completar_casilla = QtGui.QMessageBox.warning(self, 'Mensaje',
    56. "Debes completar con un ID Válido", QtGui.QMessageBox.Yes)
    57.  
    58. self.ventana.data_base.close()
    59. else:
    60. self.ventana.var_ver_si_se_puede_sacar_item.exec("SELECT * FROM items WHERE id = " + str ( (self.ventana.lineEdit_id_para_eliminar_items.text())))
    61. if self.ventana.var_ver_si_se_puede_sacar_item.numRowsAffected() > 0 :
    62. winsound.PlaySound("SystemQuestion", winsound.SND_ASYNC)
    63. self.ventana.mensaje_alerta_borrar = QtGui.QMessageBox.question(self, 'Mensaje',
    64. "¿Seguro que quieres borrar el item?", QtGui.QMessageBox.Yes |
    65. QtGui.QMessageBox.No)
    66.  
    67. if self.ventana.mensaje_alerta_borrar == QtGui.QMessageBox.Yes:
    68. winsound.PlaySound("SystemAsterisk", winsound.SND_ASYNC)
    69. self.ventana.var_sacar_model.exec("DELETE FROM items WHERE id = " + str ( (self.ventana.lineEdit_id_para_eliminar_items.text())))
    70. self.ventana.var_select_despues_de_borrar_model.setTable('items')
    71. self.ventana.var_select_despues_de_borrar_model.select()
    72. self.ventana.var_select_despues_de_borrar_model.setHeaderData(0, QtCore.Qt.Horizontal, "ID")
    73. self.ventana.var_select_despues_de_borrar_model.setHeaderData(1, QtCore.Qt.Horizontal, "Nombre")
    74. self.ventana.var_select_despues_de_borrar_model.setHeaderData(2, QtCore.Qt.Horizontal, "Cantidad")
    75. self.ventana.var_select_despues_de_borrar_model.setHeaderData(3, QtCore.Qt.Horizontal, "Precio")
    76. self.ventana.var_select_despues_de_borrar_model.setHeaderData(4, QtCore.Qt.Horizontal, "Ultima Modificacion")
    77. self.ventana.tableView_ver_items.setModel(self.ventana.var_select_despues_de_borrar_model)
    78. self.ventana.tableView_ver_items.hideColumn(5)
    79.  
    80. self.ventana.data_base.close()
    81. else:
    82. print('Cancelo')
    83. else:
    84. winsound.PlaySound("SystemHand", winsound.SND_ASYNC)
    85. self.ventana.mensaje_alerta_completar_casilla = QtGui.QMessageBox.warning(self, 'Mensaje',
    86. "Debes completar con un ID Válido", QtGui.QMessageBox.Yes)
    87.  
    88. self.ventana.data_base.close()
    To copy to clipboard, switch view to plain text mode 

    3- How can change the stylesheet (padding or text-align: center) in the field ?

    Qt Code:
    1. QHeaderView::section {
    2.  
    3. }
    4.  
    5. QLineEdit:read-only {
    6.  
    7.  
    8. }
    9.  
    10.  
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    Sorry for my english



    Thanks.-
    Last edited by onsterion; 29th March 2012 at 15:55.

  2. #2
    Join Date
    Mar 2012
    Location
    Argentine
    Posts
    2
    Qt products
    Platforms
    Windows

    Default Re: Pyhon 3 - PyQT4: Table model

    Any idea? T_T

Similar Threads

  1. PyQt4 tree model
    By MTK358 in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2011, 14:27
  2. custom model + PyQt4
    By wirasto in forum Qt Programming
    Replies: 6
    Last Post: 20th July 2009, 09:42
  3. Replies: 12
    Last Post: 5th July 2009, 17:03
  4. set color table in PyQt4
    By grissiom in forum Newbie
    Replies: 0
    Last Post: 6th April 2008, 11:22
  5. QT Table Model
    By aekilic in forum Qt Programming
    Replies: 15
    Last Post: 24th January 2007, 13:57

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.