[RQt-devel] virtual functions
Michael Lawrence
lawrence.michael at gene.com
Sat Apr 17 04:31:24 CEST 2010
On Fri, Apr 16, 2010 at 4:48 PM, John Verzani <verzani at math.csi.cuny.edu>wrote:
> I'm trying to create a virtual function to handle an event. After spending
> time with the proto package I was hoping that something like this would
> work:
>
> library(qtbase)
> e <- Qt$QLineEdit()
> e$mousePressEvent <- function(e) print("called")
>
>
While it would be possible to extend every Qt class with instance-level
"signal" handlers, this would add a significant amount of complexity. For
qtpaint, I made an RLayer class that essentially allowed this for the Layer
class.
The current design of qtpaint though is simply to follow the design of
Qt/C++ where methods are defined at the class level. There are signals for
most common things, like "clicked" for QPushButton. How often does one need
a mouse click event for QLineEdit? Qt uses signals far less than GTK+, which
makes sense, since extending a C++ class is far easier than extending a
GObject class in C.
Honestly, I kind of like forcing people to follow an OOP approach when
creating complex GUIs. Unfortunately, this might restrict some aspects of
gWidgets...
> However, it doesn't. I know how to work around this by extending the
> QLineEdit class, defining a method mousePressEvent in that class which can
> consider the state of the instance in the call. Along the lines of
>
> qsetClass("gwQLineEdit", Qt$QLineEdit, function() super(parent))
> qsetMethod("mousePressEvent", gwQLineEdit, function(e) print("do something
> depending on value of this...."))
>
> This just seems like I am doing it wrong. (For one thing it calls this
> method even if no event handler for the instance is defined.) Is there a
> better way?
>
> Thanks for any help,
>
> John
> --
> John Verzani
> Chair, Department of Mathematics
> College of Staten Island, CUNY
> verzani at math.csi.cuny.edu
>
> _______________________________________________
> Qtinterfaces-devel mailing list
> Qtinterfaces-devel at lists.r-forge.r-project.org
>
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.r-forge.r-project.org/pipermail/qtinterfaces-devel/attachments/20100416/1ebc0dce/attachment.htm
More information about the Qtinterfaces-devel
mailing list