This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Custom paintEvent for QListView problem

Tags: None
(comma "," separated)
rshah
Registered Member
Posts
13
Karma
0
OS
Hi,
Currently i'm developing this scripted plasmoid(python):
http://kde-look.org/content/show.php/On ... ent=116413.

I'm trying to add gradient effect to the top and bottom of listview,
something like krunner's query result, by porting krunner's resultview codes.

After i added the codes for gradient, my plasmoid always crash.

Below my paintevent codes:
Code: Select all
    def paintEvent(self,event):
        #taken from krunner's result view, all credit go to it's developers :)

        backBuffer = QPixmap(self.viewport().size())
        backBuffer.fill(Qt.transparent)
        backBufferPainter = QPainter(backBuffer)

        painter = QPainter(self.viewport())
        painter.setRedirected(self.viewport(),backBuffer)
        QListView.paintEvent(self,event)
        painter.restoreRedirected(self.viewport())

        gradientHeight = 48
        if (self.topFadeout.isNull() or self.topFadeout.width() != self.width()):
            g = QLinearGradient(0, 0, 0, gradientHeight)
            g.setColorAt(1, Qt.white )
            g.setColorAt(0, Qt.transparent )
            self.topFadeout = QPixmap(self.width(), gradientHeight)
            self.topFadeout.fill(Qt.transparent)
            p = QPainter(self.topFadeout)
            p.setCompositionMode(QPainter.CompositionMode_Source)
            p.fillRect(self.topFadeout.rect(), g)
       
        if (self.bottomFadeout.isNull() or self.bottomFadeout.width() != self.width()):
            g = QLinearGradient(0, 0, 0, gradientHeight)
            g.setColorAt(0, Qt.white )
            g.setColorAt(1, Qt.transparent )
            self.bottomFadeout = QPixmap(self.width(), gradientHeight)
            self.bottomFadeout.fill(Qt.transparent)
            p = QPainter(self.bottomFadeout)
            p.setCompositionMode(QPainter.CompositionMode_Source)
            p.fillRect(self.bottomFadeout.rect(), g)
       
        backBufferPainter.setCompositionMode(QPainter.CompositionMode_DestinationIn)
       
        backBufferPainter.drawPixmap(QPoint(0,0), self.topFadeout)       
        backBufferPainter.drawPixmap(QPoint(0,self.height()-self.bottomFadeout.height()), self.bottomFadeout)

        painter.drawPixmap(event.rect(), backBuffer, event.rect())



I tried to comment all paintevent codes starting from this: backBufferPainter = QPainter(backBuffer), my plasmoid didnot crash.

Any hints to solve this problem?

Thanks,
Reza
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Does it occur if you only comment the following lines?
Code: Select all
        painter = QPainter(self.viewport())
        painter.setRedirected(self.viewport(),backBuffer)
        QListView.paintEvent(self,event)
        painter.restoreRedirected(self.viewport())


If so, try renaming it something that may not already be used such as itemPainter...


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
rshah
Registered Member
Posts
13
Karma
0
OS
i changed this line:
Code: Select all
  backBufferPainter = QPainter(backBuffer)


to:
Code: Select all
   backBufferPainter = QPainter()
   backBufferPainter.begin(backBuffer)

i think somehow the problem is solved:).


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]