[solved] repaint() issue

Post here if you need help with creating a Graphical User Interface in Python.

[solved] repaint() issue

Postby Tcll » Mon Apr 21, 2014 11:26 pm

this is actually a little complex...
I've gotten everything working in UMC_SIDE using my file-system for UMC...

upon loading a file, the viewport is filled with the data asexpected:
Image

but upon resizing the viewport (or any action that calls repaint()), the text is cleared:
Image

I've tried calling paintEvent( None ), but I get the same results...

anyone think they might know any leads before I post the code??
but that being said, instead of posting alot of large sections of code, is there anything specific needed??

thanks for any and all help on this. :)
Last edited by Tcll on Tue Apr 22, 2014 5:49 am, edited 1 time in total.
User avatar
Tcll
 
Posts: 101
Joined: Wed Jan 01, 2014 6:36 pm

Re: repaint() issue

Postby Tcll » Tue Apr 22, 2014 5:32 am

here's some debug info I got from running a debug session in VS2010 and resizing after importing a file, though it's not really anything spectacular:
Image

and here's the code for paintEvent():
Code: Select all
    # most of this is still ported from my works on the original QHexEdit widget.
    def paintEvent(self, event) :
 
        painter = self._painter
        painter.begin(self.viewport())
        painter.translate(-self.horizontalScrollBar().value() * self.font_width, 0) # set scroll

        data_size     = self.data.size
        widget_height = self.height()
       
        line1 = self.hexPos
        line2 = self.textPos

        row = 0
        grayRow = False
        while self.data.offset < data_size:
            offset = self.data.offset
           
            offset2 = (offset+16 if data_size-offset>16 else data_size)
            row_data = self.data.data[ offset: offset2]
            self.data.offset = offset2

            painter.setPen(self.addressColor)
            painter.drawText(0, row, line1 * self.font_width, self.font_height, Qt.AlignTop,
                QtCore.QString( eval( '%s%i%s%i%s'%(
                    '"  %0',self.intAddrLen,'i:%0',self.hexAddrLen,'x"%(offset,offset)') ) ))
           
            hexStartPos = line1+self.font_width+int(self.font_width*.5)
            asciiStartPos = line2+int(self.font_width*.5)
           
            #Row highlight
            if grayRow: painter.fillRect( hexStartPos, row, (self.font_width*((self.row_width*3)-1)), self.font_height, self.rowColor )
               
            for i,ci in enumerate(row_data):
                index = offset + i

                isprintable = ci in self._printable
                isansi = ci in self._ansi
                iscontrol = ci in self._control

                hexPos = hexStartPos + (i * 3 * self.font_width)
                asciiPos=asciiStartPos + i * self.font_width
               
                #change address color here (after first byte)
                if isprintable: painter.setPen(self.textColor)
                elif isansi:    painter.setPen(self.ansi_text)
                elif iscontrol: painter.setPen(self.control_text)
                else:           painter.setPen(self.non_printable_text)

                #highlight coords
                if i: p,s = self.font_width, 3
                else: p,s = 0, 2


                #Selection highlight
                if self.selection_start>=0:
                    if self.selection_start<=index<=self.selection_end:
                        sp,ss = (p,s) if self.selection_start<=(index-1)<=self.selection_end else (0,2)
                        painter.fillRect( hexPos-sp, row, self.font_width*ss, self.font_height, self.selectionColor )
                        painter.fillRect( asciiPos, row, self.font_width, self.font_height, self.selectionColor )
                           
                #Column highlight
                if i in (4,12): painter.fillRect( hexPos, row, self.font_width*11, self.font_height, self.colColorDark if grayRow  else self.colColor )

                #Draw Byte
                painter.drawText( hexPos, row, self.font_width*2, self.font_height, Qt.AlignTop, ("%02x"%ci).upper())
                painter.drawText( asciiPos, row, self.font_width, self.font_height, Qt.AlignTop, self._Q_char_table[ci] )
         
            if self.show_Rows: grayRow = not grayRow
            else: grayRow = False

            row += self.font_height
           
        #draw the address line
        painter.setPen(QtGui.QPen(self.palette().shadow().color()))
        painter.drawLine(line1, 0, line1, widget_height)

        painter.end()
 
        return

as stated before...
apparently calling this after the initial display causes the text to be drawn blank... :/
User avatar
Tcll
 
Posts: 101
Joined: Wed Jan 01, 2014 6:36 pm

Re: repaint() issue

Postby Tcll » Tue Apr 22, 2014 5:47 am

and this just in... I'm the world's biggest idiot >.<
I forgot to reset the offset in the code...
first off, it's my fault for using the global file offset to go by in the first place. XD

so that's one issue fixed:
Image
now I've just got a selection issue which I can look into :P
which I can now get to. XD
User avatar
Tcll
 
Posts: 101
Joined: Wed Jan 01, 2014 6:36 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 1 guest