Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PyQt has database support (which I personally haven't used, so I can't comment on), but should be pretty straightforward documentation if you look at the QDatabase. If your application's api can always have access to Qt, this may be the best approach as they also have some additional models for mapping to the interface.</p> <p>Another alternative is going with a Python ORM (object relational mapper) such as Django, SQLAlchemy or storm and to define your table's (models) and manually load them into your designer interface.</p> <p>The way I personally do it, is I've actually built up my own ORM called ORB and a PyQt extension library called ProjexUI. The ORB library is Qt independent so it can be used in non-Qt projects, and the ProjexUI library contains mappings to help use database records in Qt widgets.</p> <p>For documentation and more information, check out: <a href="http://www.projexsoftware.com" rel="nofollow">http://www.projexsoftware.com</a></p> <p>For a simple example, create a new UI file by doing:</p> <ul> <li>Load Qt Designer</li> <li>Create a new Qt Dialog</li> <li>Drag &amp; Drop a QTreeWidget</li> <li>Right-click and do 'Change objectName...' > 'uiOrbTREE'</li> <li>Right-click on the widget and choose 'Promote to...' <ul> <li>Leave the Base class name the same (QTreeWidget)</li> <li>Set 'Promoted class name' to 'XOrbTreeWidget'</li> <li>Set 'Header file' to 'projexui.widgets.xorbtreewidget'</li> <li>Click 'Add' and then 'Promote'</li> </ul></li> <li>Select the base Dialog and click the 'Lay Out in a Grid'</li> <li>Save out the UI file (I'll refer to it as UI_FILE in the code)</li> </ul> <p>This creates the PyQt interface portion, next you'll still need to connect the interface to a database backend. The simplest example of how to do this with ORB is:</p> <pre><code># import the projexui and orb libraries import projexui import orb # import PyQt modules import PyQt4.QtGui import PyQt4.uic # create our database model class User(orb.Table): __db_columns__ = [ orb.Column( orb.ColumnType.String, 'username' ), orb.Column( orb.ColumnType.String, 'password' ), orb.Column( orb.ColumnType.Boolean, 'isActive' ) ] # the above model will by default create a PostgreSQL table called default_user with # the fields _id, username, password and is_active. All of this is configurable, but # you should read the docs for more info # create the database information db = orb.Database('Postgres', DATABASE_NAME) # set your db name db.setUsername(USER_NAME) # set your db user name db.setPassword(PASSWORD) # set your password db.setHost('localhost') # set your host db.setPort(5432) # set your port # register the database orb.Orb.instance().registerDatabase(db) # sync the datbase (this will create your tables, update columns, etc.) # NOTE: this should not always be called, it is here as an example db.sync( dryRun = False ) # dryRun will just output the SQL calls #----------------------------- # End Database Code #----------------------------- class ExampleDialog(QtGui.QDialog): def __init__( self, parent = None ): super(ExampleDialog, self).__init__(parent) # load your UI file PyQt4.uic.loadUi(UI_FILE, self) # use the UI_FILE you saved # connect the tree to the model self.uiOrbTREE.setTableType(User) # that is all you have to do to link the tree to the model and vice-versa, # this is the most simple example of how to do this - you can do more as far # as linking queries and sorting and such, but you should read the docs on # the site # launch as an application if ( __name__ == '__main__' ): # always check for an existing application first! app = None if ( not QtGui.QApplication.instance() ): app = QtGui.QApplication(sys.argv) dialog = ExampleDialog() dialog.show() # execute the app if we created it if ( app ): app.exec_() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload