[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Custom QSqlRelationalDelagate: how to change text?
From:       Simone Zaccarin <simozack () yahoo ! it>
Date:       2008-04-11 14:34:57
Message-ID: 620242.12819.qm () web25608 ! mail ! ukl ! yahoo ! com
[Download RAW message or body]

My only problem is that I construct the UI via QtDesigner. Is there a way to "overwrite" the table added via Designer without being a PyQt4 expert?

:D

Simone

----- Messaggio originale -----
Da: Mark Summerfield <mark@qtrac.eu>
A: pyqt@riverbankcomputing.com
Cc: Simone Zaccarin <simozack@yahoo.it>
Inviato: Venerd́ 11 aprile 2008, 16:02:12
Oggetto: Re: [PyQt] Custom QSqlRelationalDelagate: how to change text?

On 2008-04-11, Simone Zaccarin wrote:
> I'm trying to create a custom QSqlRelationalDelegate.
>
> In the database, the date field is in text form 'yyyy-MM-dd'. I have to
> show that string in a QSqlTable in the form 'dd-MM-yyyy'.

If that's the only change you want to make, you could try what might be
a simpler approach, such as subclassing QRelationalTableModel and
reimplementing the data() method. For every column except the date just
pass the work to the base class, and for your date column do something
like:
    
    dateString = index.model().data(index).toString() return
    return QDate.fromString(dateString, "yyyy-MM-dd").toString("dd/MM/yyyy")


> I think to overwrite the paint method of the QSqlRelationalDelegate, but
> the result is not what I'm expeting: the text and the background of the
> cells are black.
>
> How can I simple change the text without changing anything else in the
> paint method? Has anyone an example on that?
>
> This is the source of my custom paint method (I derived this the code from
> the PyQt book examples):
>
> def paint(self, painter, option, index):
>         if index.column() == 1:
>             myoption = QStyleOptionViewItem(option)
>             text = index.model().data(index).toString()
>             palette = QApplication.palette()
>             document = QTextDocument()
>             document.setDefaultFont(option.font)
>             document.setDefaultTextOption(option.color)
>             value_list = text.split('-')
>             year, month, day = value_list
>             date = QString(QDate(int(year), int(month),
> int(day)).toString('dd/MM/yyyy')) document.setPlainText(date)
>             color = palette.highlight().color() if option.state &
> QStyle.State_Selected \ else QColor(index.model().data(index,
> Qt.BackgroundColorRole)) painter.save()
>             painter.fillRect(option.rect, color)
>             painter.translate(option.rect.x(), option.rect.y())
>             document.drawContents(painter)
>             painter.restore()
>         else:
>             QSqlRelationalDelegate.paint(self, painter, option, index)
>
> I'm on WinXp SP2, PyQt 4.3.3 and Python 2.5.2.
> Thanks,
> Simone
>
>
>
>
>       Inviato da Yahoo! Mail.
> La casella di posta intelligente.
> http://it.docs.yahoo.com/mail/overview/index.html
>
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu






      Inviato da Yahoo! Mail. 
La casella di posta intelligente.
http://it.docs.yahoo.com/mail/overview/index.html

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic