Is there any way to change the cursor shape when the cursor is over
some specific column of a wx.Grid (returning to the default shape when
the mouse moves away from that specific column)?
Specifically, I am trying to make the contents of a specific column in
the grid to emulate a hyperlink -- when the user selects a cell in
that column, the font changes to usual hyperlink colors and syle and
the cursor should also change to a pointing hand. So, inside the grid
SelectCellEvent I did the following:
def OnResourceGridSelectCell(self, evt):
row, col = evt.GetRow(), evt.GetCol()
if col == 3:
self.ResourceGrid.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
size = font.GetPointSize()
self.ResourceGrid.SetReadOnly(row, col)
self.ResourceGrid.SetCellTextColour(row, col, wx.BLUE)
self.ResourceGrid.SetCellFont(row, col, wx.Font(size,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL, True))
evt.Skip()
The font color and style change, but not the cursor shape. Any hints?
Thanks in advance!
With warmest regards,
···
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@gmail.com
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."
Is there any way to change the cursor shape when the cursor is over
some specific column of a wx.Grid (returning to the default shape when
the mouse moves away from that specific column)?
Specifically, I am trying to make the contents of a specific column in
the grid to emulate a hyperlink -- when the user selects a cell in
that column, the font changes to usual hyperlink colors and syle and
the cursor should also change to a pointing hand. So, inside the grid
SelectCellEvent I did the following:
def OnResourceGridSelectCell(self, evt):
row, col = evt.GetRow(), evt.GetCol()
if col == 3:
self.ResourceGrid.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
size = font.GetPointSize()
self.ResourceGrid.SetReadOnly(row, col)
self.ResourceGrid.SetCellTextColour(row, col, wx.BLUE)
self.ResourceGrid.SetCellFont(row, col, wx.Font(size,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL, True))
evt.Skip()
The font color and style change, but not the cursor shape. Any hints?
You'll need to bind a handler for EVT_MOTION to the window returned from GetGridWindow(). In the handler be sure to call Skip so the grid's default mouse handlers will be run. Check if the position of the mouse event is inside the column (you'll have to convert the pixel position of the event, adjusted by the scroll offset, to the column number,) and if so call GetGridWindow().SetCursor passing it the cursor you want to use. Be sure to also handle the case where you've set your cursor and the mouse pointer is moved outside of your special column and then change the cursor back to the default.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Thank you very much again for you help. After your suggestion, I
learned about the EVT_MOTION event and GetGridWindow() searching
Google.
However, for the time being, I have solved the problem in a much LESS
ellegant (but simpler) way, as follows:
def OnResourceGridSelectCell(self, evt):
row, col = evt.GetRow(), evt.GetCol()
grid_win = self.ResourceGrid.GetGridWindow()
if col == 3:
grid_win.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
size = font.GetPointSize()
self.ResourceGrid.SetReadOnly(row, col)
self.ResourceGrid.SetCellTextColour(row, col, wx.BLUE)
self.ResourceGrid.SetCellFont(row, col, wx.Font(size,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL, True))
else:
grid_win.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
evt.Skip()
Binding a handler to EVT_MOTION is of course much more ellegant, and I
will implement that later on.
Again, thank you VERY MUCH!
With warmest regards,
···
2009/5/5 Robin Dunn <robin@alldunn.com>:
Mauro Cavalcanti wrote:
Dear ALL,
Is there any way to change the cursor shape when the cursor is over
some specific column of a wx.Grid (returning to the default shape when
the mouse moves away from that specific column)?
Specifically, I am trying to make the contents of a specific column in
the grid to emulate a hyperlink -- when the user selects a cell in
that column, the font changes to usual hyperlink colors and syle and
the cursor should also change to a pointing hand. So, inside the grid
SelectCellEvent I did the following:
def OnResourceGridSelectCell(self, evt):
row, col = evt.GetRow(), evt.GetCol()
if col == 3:
self.ResourceGrid.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
size = font.GetPointSize()
self.ResourceGrid.SetReadOnly(row, col)
self.ResourceGrid.SetCellTextColour(row, col, wx.BLUE)
self.ResourceGrid.SetCellFont(row, col, wx.Font(size,
wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL, True))
evt.Skip()
The font color and style change, but not the cursor shape. Any hints?
You'll need to bind a handler for EVT_MOTION to the window returned from
GetGridWindow(). In the handler be sure to call Skip so the grid's default
mouse handlers will be run. Check if the position of the mouse event is
inside the column (you'll have to convert the pixel position of the event,
adjusted by the scroll offset, to the column number,) and if so call
GetGridWindow().SetCursor passing it the cursor you want to use. Be sure to
also handle the case where you've set your cursor and the mouse pointer is
moved outside of your special column and then change the cursor back to the
default.
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@gmail.com
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."