Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-10

How to create a non focusable form?

19 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi All,

I want to create a borderless non modal form (native Windows and Linux-Qt) which not catch the focus on mouse click. Tried with modified ControlStyle and CanFocus override but without success. Any other idea?

Gabor

Reply by email

Ondrej Pokorny
to Gabor Boros
Gabor Boros wrote 6 lines
Hi All, I want to create a borderless non modal form (native Windows and Linux-Qt) which not catch the focus on mouse click. Tried with modified ControlStyle and CanFocus override but without success. Any other idea?

IIRC you can use THintWindow as ancestor. See particularly THintWindow.WMNCHitTest that does the job.

Ondrej

Reply by email

Ondrej Pokorny
to Gabor Boros: I want to create a borderless non modal form (native Windows and Linux-Qt) which not…
Gabor Boros wrote 6 lines
Hi All, I want to create a borderless non modal form (native Windows and Linux-Qt) which not catch the focus on mouse click. Tried with modified ControlStyle and CanFocus override but without success. Any other idea?

IIRC you can use THintWindow as ancestor. See particularly THintWindow.WMNCHitTest that does the job.

Ondrej

Reply by email

Zeljko
to Gabor Boros: I want to create a borderless non modal form (native Windows and Linux-Qt) which not…
Gabor Boros wrote 5 lines
Hi All, I want to create a borderless non modal form (native Windows and Linux-Qt) which not catch the focus on mouse click. Tried with modified ControlStyle and CanFocus override but without success. Any other idea?

csNoFocus does not work for Qt ? Can you provide example ? For Qt: before example try to include qt4 and qtwidgets into your unit and then
in CreateWnd of your custom form (or after form handle is created)

TQtMainWindow(YourForm.Handle).SetFocusPolicy(QtNoFocus);
TQtMainWindow(YourForm.Handle).WindowArea.SetFocusPolicy(QtNoFocus);

zeljko

Reply by email

Zeljko
to Zeljko
Zeljko wrote 16 lines
On 10/27/2015 04:04 PM, Gabor Boros wrote: > Hi All, > > I want to create a borderless non modal form (native Windows and > Linux-Qt) which not catch the focus on mouse click. Tried with modified > ControlStyle and CanFocus override but without success. Any other idea? csNoFocus does not work for Qt ? Can you provide example ? For Qt: before example try to include qt4 and qtwidgets into your unit and then in CreateWnd of your custom form (or after form handle is created) TQtMainWindow(YourForm.Handle).SetFocusPolicy(QtNoFocus); TQtMainWindow(YourForm.Handle).WindowArea.SetFocusPolicy(QtNoFocus);

Of course , you can try with THintWindow as Ondrej mentioned, but if form is bsNone than it should not take focus. Don't know what happens with framed forms on linux....if you click on frame then X11 rules are unpredictible.
Also, you can set QWidget attribute QtWA_ShowWithoutActivating, but that should be setted up before form is shown (eg in FormCreate call HandleNeeded and set focusPolicy and attributes). See QtWSControls/qtint, there's dnd imagelist operation and we are using ShowWithoutActivating etc ...

zeljko

Reply by email

Gabor Boros
to Zeljko: csNoFocus does not work for Qt ? Can you provide example ? For Qt: before example try to…

2015.10.27. 16:16 keltez?ssel, Zeljko ?rta:

Show quoted text 8 lines
csNoFocus does not work for Qt ? Can you provide example ? For Qt: before example try to include qt4 and qtwidgets into your unit and then in CreateWnd of your custom form (or after form handle is created) TQtMainWindow(YourForm.Handle).SetFocusPolicy(QtNoFocus); TQtMainWindow(YourForm.Handle).WindowArea.SetFocusPolicy(QtNoFocus);

WindowArea not exist, found ScrollAera which is TQtWindowArea type. But not have any effect for me. Example attached (without Qt and WMNCHitTest trick).

Gabor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Form_Focus.tar.gz
Type: application/gzip
Size: 1728 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151027/52c56fd2/attachment-0001.bin>

Reply by email

Zeljko
to Gabor Boros
Gabor Boros wrote 11 lines
2015.10.27. 16:16 keltez?ssel, Zeljko ?rta: > > csNoFocus does not work for Qt ? Can you provide example ? > For Qt: before example try to include qt4 and qtwidgets into your unit > and then > in CreateWnd of your custom form (or after form handle is created) > > TQtMainWindow(YourForm.Handle).SetFocusPolicy(QtNoFocus); > TQtMainWindow(YourForm.Handle).WindowArea.SetFocusPolicy(QtNoFocus); WindowArea not exist, found ScrollAera which is TQtWindowArea type.

Yes, sorry, I've mistyped ... written from memory.

But not have any effect for me. Example attached (without Qt and WMNCHitTest trick).

WMNCHitTest is windows only thing afair, but I'll check your example with Qt under linux.

zeljko

Reply by email

Zeljko
to Gabor Boros: 2015.10.27. 16:16 keltez?ssel, Zeljko ?rta: WindowArea not exist, found ScrollAera which…
Gabor Boros wrote 13 lines
2015.10.27. 16:16 keltez?ssel, Zeljko ?rta: > > csNoFocus does not work for Qt ? Can you provide example ? > For Qt: before example try to include qt4 and qtwidgets into your unit > and then > in CreateWnd of your custom form (or after form handle is created) > > TQtMainWindow(YourForm.Handle).SetFocusPolicy(QtNoFocus); > TQtMainWindow(YourForm.Handle).WindowArea.SetFocusPolicy(QtNoFocus); WindowArea not exist, found ScrollAera which is TQtWindowArea type. But not have any effect for me. Example attached (without Qt and WMNCHitTest trick).

Please test with attached patch and give feedback. Note that this patch is tested under Qt X11 only.

zeljko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_activation_fix.diff
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151028/4da5f2f8/attachment.bin>

Reply by email

Gabor Boros
to Zeljko

2015.10.28. 10:59 keltez?ssel, Zeljko ?rta:

Show quoted text 5 lines
Please test with attached patch and give feedback. Note that this patch is tested under Qt X11 only. zeljko

With the original example works but...

Modified the example...

procedure TForm1.Button1Click(Sender: TObject);
var
   MyForm:TMyForm;
begin
   MyForm:=TMyForm.CreateNew(Nil);
   with TButton.Create(MyForm) do Parent:=MyForm;
   MyForm.Show;
end;

The button appear on the form only if modify ControlStyle in the example from

ControlStyle:=ControlStyle+[csNoFocus,csNoStdEvents]-[csCaptureMouse,csClickEvents];
  to
ControlStyle:=ControlStyle+[csNoFocus]-[csCaptureMouse,csClickEvents];

(csNoStdEvents removed) but after form grab focus if click on it or click on the button.

Gabor

Reply by email

Zeljko
to Gabor Boros
Gabor Boros wrote 30 lines
2015.10.28. 10:59 keltez?ssel, Zeljko ?rta: > > Please test with attached patch and give feedback. Note that this patch > is tested under Qt X11 only. > > zeljko With the original example works but... Modified the example... procedure TForm1.Button1Click(Sender: TObject); var MyForm:TMyForm; begin MyForm:=TMyForm.CreateNew(Nil); with TButton.Create(MyForm) do Parent:=MyForm; MyForm.Show; end; The button appear on the form only if modify ControlStyle in the example from ControlStyle:=ControlStyle+[csNoFocus,csNoStdEvents]-[csCaptureMouse,csClickEvents]; to ControlStyle:=ControlStyle+[csNoFocus]-[csCaptureMouse,csClickEvents];

I'll check that. csNoStdEvent is passed to form inside Qt widgetset

(csNoStdEvents removed) but after form grab focus if click on it or click on the button.

Ok, then go to QtWSForms, TQtWSCustomForms.UpdateWindowFlags and comment if csNoStdEvents ..... leave only
Flags := Flags or QtX11BypassWindowManagerHint;

in this case form will not take focus in any case, but must see what happens with parenting (button is not visible because of this param I guess).

zeljko

Reply by email

Gabor Boros
to Zeljko

2015.10.28. 11:51 keltez?ssel, Zeljko ?rta:

Show quoted text 7 lines
Ok, then go to QtWSForms, TQtWSCustomForms.UpdateWindowFlags and comment if csNoStdEvents ..... leave only Flags := Flags or QtX11BypassWindowManagerHint; in this case form will not take focus in any case, but must see what happens with parenting (button is not visible because of this param I guess).

Commented out "if csNoStdEvents..." line. Button not visible on form with out without csNoStdEvents in ControlStyle.

Gabor

Reply by email

Zeljko
to Gabor Boros: 2015.10.28. 11:51 keltez?ssel, Zeljko ?rta: Commented out "if csNoStdEvents..." line.…
Gabor Boros wrote 11 lines
2015.10.28. 11:51 keltez?ssel, Zeljko ?rta: > Ok, then go to QtWSForms, TQtWSCustomForms.UpdateWindowFlags and comment > if csNoStdEvents ..... leave only > Flags := Flags or QtX11BypassWindowManagerHint; > > in this case form will not take focus in any case, but must see what > happens with parenting (button is not visible because of this param I > guess). Commented out "if csNoStdEvents..." line. Button not visible on form with out without csNoStdEvents in ControlStyle.

Yes, QtX11BypassWindowManagerHint does strange things and that's not documented in Qt :(
Really don't know how to achive that goal under X11. Tried pure Qt application and have same problem. Shown form does not activate and that's fine, but when I click on it then it activates :(

zeljko

Reply by email

Zeljko
to Gabor Boros: 2015.10.28. 11:51 keltez?ssel, Zeljko ?rta: Commented out "if csNoStdEvents..." line.…
Gabor Boros wrote 11 lines
2015.10.28. 11:51 keltez?ssel, Zeljko ?rta: > Ok, then go to QtWSForms, TQtWSCustomForms.UpdateWindowFlags and comment > if csNoStdEvents ..... leave only > Flags := Flags or QtX11BypassWindowManagerHint; > > in this case form will not take focus in any case, but must see what > happens with parenting (button is not visible because of this param I > guess). Commented out "if csNoStdEvents..." line. Button not visible on form with out without csNoStdEvents in ControlStyle.

seem that we are not lucky with Qt4.
I've readed a bit Qt5 docs and it seem that it's fixed there with new attributes like:Qt::WA_X11DoNotAcceptFocus and windowFlags like Qt::WindowDoesNotAcceptFocus.

zeljko

Reply by email

Zeljko
to Gabor Boros: 2015.10.28. 11:51 keltez?ssel, Zeljko ?rta: Commented out "if csNoStdEvents..." line.…
Gabor Boros wrote 11 lines
2015.10.28. 11:51 keltez?ssel, Zeljko ?rta: > Ok, then go to QtWSForms, TQtWSCustomForms.UpdateWindowFlags and comment > if csNoStdEvents ..... leave only > Flags := Flags or QtX11BypassWindowManagerHint; > > in this case form will not take focus in any case, but must see what > happens with parenting (button is not visible because of this param I > guess). Commented out "if csNoStdEvents..." line. Button not visible on form with out without csNoStdEvents in ControlStyle.

Please check with attached patch (same name as previous one). Seem that our C bindings does not have all attributes translated since they did not exist in Qt-4.5, but sometime later. I've added strict X11 attribute and now it does not steal activation or focus, even if clicked with mouse (tested with your example with button).

zeljko

-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_activation_fix.diff
Type: text/x-patch
Size: 987 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151028/8e65fdd9/attachment.bin>

Reply by email

Gabor Boros
to Zeljko

2015.10.28. 14:12 keltez?ssel, Zeljko ?rta:

Show quoted text 6 lines
Please check with attached patch (same name as previous one). Seem that our C bindings does not have all attributes translated since they did not exist in Qt-4.5, but sometime later. I've added strict X11 attribute and now it does not steal activation or focus, even if clicked with mouse (tested with your example with button).

Tested with fixes_1_4 and trunk. Works like a charm! :D Thank you very much!

Report as a bug in the tracker?

A previous fix... Please add commit 50139 to merge requests for fixes_1_4.

Gabor

Reply by email

Zeljko
to Gabor Boros
Gabor Boros wrote 12 lines
2015.10.28. 14:12 keltez?ssel, Zeljko ?rta: > > Please check with attached patch (same name as previous one). Seem that > our C bindings does not have all attributes translated since they did > not exist in Qt-4.5, but sometime later. I've added strict X11 attribute > and now it does not steal activation or focus, even if clicked with > mouse (tested with your example with button). Tested with fixes_1_4 and trunk. Works like a charm! :D Thank you very much! Report as a bug in the tracker?

Yes please, attach there example and my latest patch :)

A previous fix... Please add commit 50139 to merge requests for fixes_1_4.

Done.

zeljko

Reply by email