views:

34

answers:

1

Python 2.5.4 PyQt4

I sub-classed a QDoubleSpinBox to emit a signal on a focusIn event:



#Custom widgets for DPL GUI
from PyQt4.QtCore import * 
from PyQt4.QtGui import * 

class DPLDoubleSpinBox(QDoubleSpinBox):

    __pyqtSignals__ = ("valueChanged(double)", "focusIn()")

    def __init__(self, *args):
        QDoubleSpinBox.__init__(self, *args)

    def event(self, event):
        if(event.type()==QEvent.FocusIn):
            self.emit(SIGNAL("focusIn()"))
            #self.clear() Works as expected
            self.selectAll() #See below                  

        return QDoubleSpinBox.event(self, event)

if __name__ == "__main__":

    import sys

    app = QApplication(sys.argv)
    widget = DPLDoubleSpinBox()
    widget2 = DPLDoubleSpinBox()
    widget.show()
    widget2.show()
    sys.exit(app.exec_())

If you click inside one box, then kill the other window, it works. If you click inside one, then the other, then focus any other window on the desktop, it seems to work.

I think it's a focus problem, but can't track it down. I just need it to select all when clicked on. I tried doing it through its line edit pointer, but I get the same results. Tried forcing focus to other widgets, but still same result.

You can connect a custom slot to fire when it emits "focusIn()". You can then anyQSpinBox.selectAll(), and it works, just not on itself.

A: 

I changed the event to QEvent.Enter

Now it will self.selectAll()

I can get away with this because it's for a touch screen application, so it wouldn't be obvious to the user that something is amiss. I'd still love to know what I'm missing, or if this is just a bug.

WoggleCrab