python - PyQt4 qTableView Alignment -


Can anyone help me in anticipation - I spent some days but no luck ...

I'm using PyQt, and some qTableViews to display some data - now I want to align this data in the center.

is under my code -.! Ui_manual_matching.table_unmatched_flights is qTableView object

Thanks a lot

Adam

  db = QSqlDatabase.addDatabase ("QSQLITE") db.setDatabaseName (settings. Str_combined_database) #create filter by db.open () bor you with a SQL (I description) flights_table_model = QSqlTableModel () flights_table_model.setTable ('eg_table') flights_table_model.setFilter (str_eg_filter) flights_table_model.select () ui_manual_matching .table_unmatched_flights.setModel (flights_table_model)   

'

QSqlTableModel should be able to be able to get it through subclass and data () method should override. Something like this should do the trick

  class MySqlModel (QSqlTableModel): def data (self, index, role = Qt.DisplayRole): if role == Qt.TextAlignmentRole: Return Qt.AlignCenter return QSqlTableModel .data (self, index, role)   

This will protect the behavior of QSqlTableModel except you, now that the scene asks for text alignment, Your model gives alignment you want. You can of course select alignment using other flags () and even more logic to set different alignment based on the model index passed in the data () method can add. Do not forget to wait for your code instead of using this new model in PS, in your code, replace with flight_table_model = QSqlTableModel () with flights_table_model = MySqlModel ()

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -