Delphi: cursor over certain part of component - image

Picture on the TImage is divided on a number of small rectangles and i need to check if user clicks on one of them. Basically, i need to create button on image without button itself. So, the question is: how to check if cursor is over a certain part of Image component?

Add an OnMouseDown or OnMouseUp event handler to TImage and check X and Y params.

Related

How to add an image by pressing a button in JavaFX

I want to be able to press a button and an image appear on the page.
Additionally, I want to be able to place the button with Y and X coordinates, not through layouts.
Would I need to use an image view?
Your question isn't very precise, so I hope I answer what you need.
To show an Image generally you need an ImageView, that is correct. For less common image formats you might need an external library.
To only show the image when the button is clicked, you have to first set the ImageView to not managed and not visible. Then when the button is clicked make it visible and managed and it will show.
About the absolute positioning of your button, you can override the layout children of any Parent object and set exact positions. Take a look at this question.

Drag and Drop functionality using testcomplete

I want to simulate a drag and drop functionality from one DevXtraGridcell to another DevXtraGridcell without using the coordinate system.
Can someone give me an idea how can I do it without the default record and play and without the source and destination cordinates.
The Drag action always uses coordinates, but you can calculate the coordinates on the fly instead of using hard-coded coordinates:
Explore your grid in TestComplete's Object Browser and find a method or property that returns cell coordinates.
According to this old blog post, it should be something like:
gridObj.MainView.ViewInfo.RowsInfo.GetInfoByHandle(Row).Cells.Item_2(Column).Bounds
Calculate the coordinates of the first and second cell. (Make sure that both cells are visible on the screen.)
Do the Drag from one first cell's coordiantes to the second cell's coordinates.
in my case i had to user the obj.MainView.get_ViewInfo property worked for one gridcontrol , the other is of card layout the link given doesnt work in my case though

Oracle Forms: execute on canvas load

I have a form with 2 canvases. The first canvas has a button that loads the second canvas when pressed. Now I want to fill some data in a list item (that is in the second canvas) when the second canvas is loaded. There's the WHEN_NEW_ITEM_INSTANCE trigger on the list item but that doesn't seem to fire when the canvas is loaded. Any idea how I could do this?
Tried searching all around but haven't found anything useful.
Just put your code in the button WHEN-BUTTON-PRESSED if there is no other way to reach second canvas.

Place a window behind any other existing third party window

In order to take a screenshot of a specific window, I need to place a white colored TForm behind that window. What Windows API could I use to change the z-order of my window and place it correctly ?
Try the SetWindowPos() function.
On Delphi you can useSendToBack method, .Top and .Left properties.
form1.Top := ...;
form1.Left := ...;
form1.SendToBack;
procedure SendToBack;
Description
Use SendToBack to change the order of
overlapping controls or forms.
The order in which controls stack on
top of each other (also called the Z
order) depends on the order the
controls are placed on the form. For
example, if you put a label and an
image on a form so that one is on top
of the other, the one that was placed
first on the form becomes the one on
the bottom. Because both the label and
the image are non-windowed controls,
they "stack" as you would expect them
to. Call the SendToBack method for the
top object to move it below the other
object.
The stacking order of two windowed
controls is the same as the stacking
of two non-windowed controls. For
example, if you put a memo on a form,
then put a check box on top of it, the
check box remains on top. Calling
SendToBack for the check box makes the
memo appear on top.
The stacking order of windowed and
non-windowed controls cannot be
mingled. For example, if you put a
memo, a windowed control, on a form,
and then put a label, a non-windowed
control, on top of it, the label
disappears behind the memo. Windowed
controls always stack on top of
non-windowed controls. In this
example, calling the SendToBack method
of the memo does nothing, the label
remains behind the memo.
If the control has the input focus
when the SendToBack method executes,
it loses the input focus.
(Edit: WinSnap is a very good utility for taking and editing screenshots)
If you can get the handle of the window you want in front then I would assume that:
Pseudo Code:
MyAppWindow.BringToFront
followed by
TargetWindow.BringToFront
Should have the desired effect, yes?

What is the best way to make a QTableView's cells have up and down button pushed states in Qt?

I'm trying to make the cells of a QTableView look like 3D clickable buttons. So that when you click on a cell, the button looks pushed. Everyone seems to think I merely want to change the colour, I need to show images of a normal button, and a pushed button, that look 3-dimensional.
I have done this already with calling QTableView::setItemDelegate(), with an appropriate ItemDelegate that will change the background of the cell when it's clicked. However I'm stuck at this point because I want some cells to be different coloured buttons based on the data they contain. So a cell with a low number would be a red button, that's also red when it's clicked, and the other cells would be different colours.
I can set the colour of the button with the TableModel, but once the button is clicked, there is no way for the ItemDelegate to know that it's supposed to be a different colour than the rest. How can you link the two so the ItemDelegate knows what colour it's supposed to be?
Also, is there simply a better way to make cells look like buttons?
You can call QModelIndex::model() from within the ItemDelegate's paint() method, since it has a QModelIndex parameter. This gives you the TableModel for the data, which you can programatically decide what colour the cell's button will be.
However, this is still not as elegant as I'd hope. Does anyone know a better way to change the appearance of table cells when in both the up and down button push states?
Why don't you asked the index for the background color.
Something like this ...
QStyleOptionToolButton buttonOption;
const QStyleOptionViewItemV4& optionV4 = dynamic_cast<QStyleOptionViewItemV4&>(option);
//...
buttonOption.palette.setBrush( QPalette::Button, index.data( Qt::BackgroundColorRole ) );
//...
I have feeling that its a bug in Qt and its must have been ...
// model code
if(role==Qt::BackgroundColorRole )
return qvariant_cast<QBrush>( QBrush(Qt::red) );
// delegate code
buttonOption.palette.setBrush(QPalette::Button, optionV4.backgroundBrush );
Because the optionV4.backgroundBrush is correct in the sizeHint method but is invalid in the paint method . I see now reason why the sizeHint should have the background brush and the paint method not. I'll report it to Nokia.
EDIT:
Looks like I was right and its a bug in < Qt4.5.
QStyleOptionViewItemV4 doesn't copy the icon and backgroundBrush
Can you not get the ID/row count of the table cell's row and then check it against the colour table that you may be having, and set the colour accordingly? I am not sure if I understood your question well or not.
Assign a data role for the background color, and in your item delegate, ask the model index what it's background color is (using data( bg_color_role ) or something similar). Then, in your model, you need to make sure the data function returns a color for the bg_color_role that is appropriate for the data being modeled.
The way to do that is to use the data method of the QModelIndex object you get on the paint method, and ask for a specific role (if you define a custom model, you can add your own roles, and give the information you need to the delegate in those roles.)
TimW, I think you have to fill the QStyleOptionViewItemV4 info by calling initStyleOption before.
I'm not sure where the requirement for a background image comes from. If you want the cells to look like QPushButtons, you should probably inherit from QItemDelegate and implement paint() to use QStyle to draw you a QPushButton, something like this:
QStyleOptionButton opt;
// fill 'opt' from the information from the model, and the style option that's passed in
style()->drawControl( QStyle::CE_PushButton, &opt, painter );
Have you tried using custom style sheets?
You could just apply the same stylesheet to every cell, and then change the background image / style to draw the 3D button images depending on whether or not it's selected.

Resources