Results 1 to 7 of 7

Thread: custom model + PyQt4

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Wink Re: custom model + PyQt4

    Someone give me a sample code

    Qt Code:
    1. def data(self, index, role):
    2. value=QSqlQueryModel.data(self, index, role)
    3. if role == Qt.TextAlignmentRole:
    4. if (index.column()==2):
    5. return QVariant(Qt.AlignRight)
    6. return value
    To copy to clipboard, switch view to plain text mode 


    i hope can be useful for others

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: custom model + PyQt4

    Quote Originally Posted by wirasto View Post
    And your sample, the same as that in there. But unfortunately code like that do not display data.
    That's because it is only a part out of the whole function. You have to respect the other roles by yourself or - as below - call the base class.

    Quote Originally Posted by wirasto View Post
    Qt Code:
    1. def data(self, index, role):
    2. value=QSqlQueryModel.data(self, index, role)
    3. if role == Qt.TextAlignmentRole:
    4. if (index.column()==2):
    5. return QVariant(Qt.AlignRight)
    6. return value
    To copy to clipboard, switch view to plain text mode 
    For speed and performance issues you should better use:
    python Code:
    1. def data(self, index, role):
    2. if role == Qt.TextAlignmentRole:
    3. if (index.column()==2):
    4. return QVariant(Qt.AlignRight)
    5. return QSqlQueryModel.data(self, index, role)
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    wirasto (20th July 2009)

Similar Threads

  1. Replies: 12
    Last Post: 5th July 2009, 16:03
  2. custom widget and model
    By asieriko in forum Qt Programming
    Replies: 2
    Last Post: 6th October 2008, 14:11
  3. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  4. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41
  5. Treeview and custom model
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2007, 13:54

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
  •  
Qt is a trademark of The Qt Company.