* * *

Author Topic: How to enable OnMouseEnter event when object is not visible  (Read 582 times)

witenite

  • New member
  • *
  • Posts: 24
How to enable OnMouseEnter event when object is not visible
« on: August 12, 2018, 09:23:55 am »
Hi,
I've made some really good progress today, but am firmly stuck with this! I have a "Form" that is configured to provide an Alphablend over the main form. It acts as a highlighter for a row of data, and is supposed to move up and down the main form, depending on where the mouse is located. I have all this working, and as I have a row of TEdit boxes down the left hand side, I have a common event that is triggered by these TEdit boxes, whenever the mouse enters or hovers over one of them.

However, I want the horizontal bar to highlight the respective row of data, regardless of where the mouse is located from a latitude perspective. My idea is to use a series of panels (only need 5 of them) that span the width of the of the main form. Then, when entered, they trigger the event mentioned above.

However what I have found is that as soon as the panel/s are hidden (Visible = False) all the events for that panel/s are disabled! Note the "data" I'm talking about is a number of labels etc. that are spread across 3 separate panels, IE not a table. If I had another means of detecting when "Zones" are entered for the main form, that would work too, but for now I'm thinking that a series of hidden panels or similar are the more likely solution.

See the attachment which shows more clearly what I'm trying to achieve, where the  blue overlay/highlight needs to shift to the respective row (1 of 5), depending on mouse position anywhere within a given (row) region.

Any suggestions? I have literally spent hours trying to resolve this.
« Last Edit: August 12, 2018, 01:02:27 pm by witenite »

Pascal

  • Hero Member
  • *****
  • Posts: 742
Re: How to enable OnMouseEnter event when object is not visible
« Reply #1 on: August 12, 2018, 09:46:00 am »
I can not quite follow your description but i think you can uses the parent panel's OnMouseEnter. (The parent of the hidden panel)
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

lucamar

  • Full Member
  • ***
  • Posts: 232
Re: How to enable OnMouseEnter event when object is not visible
« Reply #2 on: August 12, 2018, 01:23:22 pm »
Controls with Visible = False never receive interaction events: after all, those events can't happen if you're not there, can they?

One relatively common solution is to use OnMouseMove of the parent to calculate which (hidden) control should be under the mouse cursor and make it visible or whatever other action you need to perform.

Another solution is to have a small visible control (e.g. a button) in whose OnMouseEnter handler you can then do whatever you want.

NOTE: It may well be posible that I misunderstood what you wanted. If so, sorry!

Edited to add:
I suppose you thought and discarded it already but, why don't you use some kind of grid control (like TStringsGrid, p.e.)? Seems like it would be the better solution for you.
« Last Edit: August 12, 2018, 01:37:11 pm by lucamar »
Been there, done that ... barely kept the timelines.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/fpc 3.0.4 - Ubuntu 10, Kubuntu 14, Windows XP SP3 (Home & Prof.) and various DOS incarnations.

Thaddy

  • Hero Member
  • *****
  • Posts: 6878
Re: How to enable OnMouseEnter event when object is not visible
« Reply #3 on: August 12, 2018, 02:24:14 pm »
Controls with Visible = False never receive interaction events: after all, those events can't happen if you're not there, can they?
Indeed. But the observer pattern is implemented for the controls since they inherit from TPersistent, so he could use that.
https://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html and the likes.
« Last Edit: August 12, 2018, 02:26:28 pm by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

lucamar

  • Full Member
  • ***
  • Posts: 232
Re: How to enable OnMouseEnter event when object is not visible
« Reply #4 on: August 12, 2018, 02:46:52 pm »
@Thaddy: Hmmm... good point .. or not. I simply don't know enough about that.  ;D Time to (re-)start studying a little bit for me. Thanks! Any possibility of a tiny example?

(I hate not knowing about these things after so many years.  :'( )
Been there, done that ... barely kept the timelines.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/fpc 3.0.4 - Ubuntu 10, Kubuntu 14, Windows XP SP3 (Home & Prof.) and various DOS incarnations.

jamie

  • Hero Member
  • *****
  • Posts: 835
Re: How to enable OnMouseEnter event when object is not visible
« Reply #5 on: August 12, 2018, 11:20:23 pm »
Looks like something a StringGrid is good for.


josh

  • Hero Member
  • *****
  • Posts: 631
Re: How to enable OnMouseEnter event when object is not visible
« Reply #6 on: August 13, 2018, 03:20:43 am »
Agree a StringGrid would be a solution.

Just knocked up a quick idea use mousemove events etc and painting a tshape, maybe if you don't want to use a stringgrid, this might give a starting point.
It's not the neatest; but it works.

Implemented the mousewheel as well for convenience too

Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus