Recent

Author Topic: Qt does not position forms  (Read 740 times)

systemgvp

  • New Member
  • *
  • Posts: 46
Qt does not position forms
« on: May 10, 2026, 03:47:15 pm »
Situation:
 - kubuntu 26.04
 - lazarus 4.6
 - wayland

Using gtk3, qt5 or qt6, if I set a form position, it isn't executed. Using gtk2, it is. Example:

1. I create a new empty application
2. I set position=poDesigned
3. I add a button and associate Form1.Left:=0;
4. I compile

If I click on button1, the form doesn't move, but stays in the center of the screen.
What's missing? Why does it only work with GTK2?
On Kubuntu 25.10, Lazarus doesn't cause any problems, even on Windows.

Alexx2000

  • New Member
  • *
  • Posts: 28
Re: Qt does not position forms
« Reply #1 on: May 10, 2026, 03:52:43 pm »
Wayland does not support changing window position. GTK2 executes using Xwayland that's why it works.

Thaddy

  • Hero Member
  • *****
  • Posts: 19267
  • Glad to be alive.
Re: Qt does not position forms
« Reply #2 on: May 10, 2026, 06:35:25 pm »
Basically it should NOT work, because Xwayland <> Wayland and by now everybody knows that the cause is not Lazarus or has been sleeping under a rock.
Everybody else also knows that Wayland has by now an extended API that allows for Windowing management a bit better, but no one has implemented it yet (that includes Lazarus, but also the rest of the world except for tests).
It is rather pointless to discuss this any further. Just automatically refer to the Wayland developers.

Btw: Qt6 is a lot better than GTK2.

And you @Alexx2000 already know all that. Don't even mention GTK2 is a Qt thread.
« Last Edit: May 10, 2026, 06:38:24 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

systemgvp

  • New Member
  • *
  • Posts: 46
Re: Qt does not position forms
« Reply #3 on: May 10, 2026, 09:44:10 pm »
Yes, Qt6 is a lot better than GTK2, but unfortunately, I need to set the shape's position in my application. Are you aware of any Wayland scams?

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1285
Re: Qt does not position forms
« Reply #4 on: May 10, 2026, 10:35:51 pm »
Yes, Qt6 is a lot better than GTK2, but unfortunately, I need to set the shape's position in my application. Are you aware of any Wayland scams?

There is no immediate solution for Wayland.

The alternative, if possible in your case, would be to switch to XLibre:

Ubuntu Repository for XLibre
https://github.com/xlibre-debian/ubuntu

About XLibre:
https://github.com/X11Libre/xserver

zeljko

  • Hero Member
  • *****
  • Posts: 1951
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Qt does not position forms
« Reply #5 on: May 11, 2026, 07:27:14 am »
Yes, Qt6 is a lot better than GTK2, but unfortunately, I need to set the shape's position in my application. Are you aware of any Wayland scams?

You can use Qt6 on same system where gtk2 is used, QT_QPA_PLATFORM=xcb ./yourapp should work.

systemgvp

  • New Member
  • *
  • Posts: 46
Re: Qt does not position forms
« Reply #6 on: May 11, 2026, 08:46:38 am »
where should I put this string?

zeljko

  • Hero Member
  • *****
  • Posts: 1951
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Qt does not position forms
« Reply #7 on: May 11, 2026, 09:05:06 am »
Put it as env variable just like I shown you for test. If that works you can start your app via script. Adding it globally into your $HOME/.bashrc isn't clever idea if you're on KDE Plasma wayland because then everything will be x11/xcb...

systemgvp

  • New Member
  • *
  • Posts: 46
Re: Qt does not position forms
« Reply #8 on: May 11, 2026, 02:47:13 pm »
Sorry, but I don't understand where to insert the variable. Where is this test?

zeljko

  • Hero Member
  • *****
  • Posts: 1951
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Qt does not position forms
« Reply #9 on: May 11, 2026, 03:00:17 pm »
In linux terminal: QT_QPA_PLATFORM=xcb ./yourapp , or if you run app via lazrus debugger, Run -> Run parameters -> click second tab "Environment", click Add button below, write env variable name QT_QPA_PLATFORM, for value set xcb, now run your qt6 app.

systemgvp

  • New Member
  • *
  • Posts: 46
Re: Qt does not position forms
« Reply #10 on: May 12, 2026, 12:08:36 am »
Thanks, both solutions work with QT6. I hope they are only a temporary solution.

dbannon

  • Hero Member
  • *****
  • Posts: 3825
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Qt does not position forms
« Reply #11 on: May 12, 2026, 03:19:23 pm »
You can also add a command line parameter if thats more intuitive -

Code: Pascal  [Select][+][-]
  1. $> my-app -platform xcb

Note its only one dash (should be two) and no '=' but the parameter is filtered out by Qt before it gets to your app, so does not cause problems with your command line parsing.

Davo
Lazarus 4, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Fred vS

  • Hero Member
  • *****
  • Posts: 3943
    • StrumPract is the musicians best friend
Re: Qt does not position forms
« Reply #12 on: May 12, 2026, 05:32:55 pm »
Gemini propose this:

Code: Pascal  [Select][+][-]
  1. program YourAppName;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF LINUX}
  7.   Unix, // Required for fpGetEnv and fpSetEnv
  8.   {$ENDIF}
  9.   Interfaces, // Initializes the Lazarus widgetset
  10.   Forms,
  11.   Unit1;
  12.  
  13. {$IFDEF LINUX}
  14. procedure CheckAndForceXCB;
  15. var
  16.   SessionType: String;
  17. begin
  18.   // Retrieve the current desktop session type
  19.   SessionType := LowerCase(fpGetEnv('XDG_SESSION_TYPE'));
  20.  
  21.   // If running on Wayland, force Qt to fallback to XCB (via XWayland)
  22.   if SessionType = 'wayland' then
  23.   begin
  24.     fpSetEnv('QT_QPA_PLATFORM', 'xcb', 1);
  25.   end;
  26. end;
  27. {$ENDIF}
  28.  
  29. begin
  30.   {$IFDEF LINUX}
  31.   // This must execute before the Interfaces unit initializes Qt
  32.   CheckAndForceXCB;
  33.   {$ENDIF}
  34.  
  35.   Application.Initialize;
  36.   Application.CreateForm(TForm1, Form1);
  37.   Application.Run;
  38. end.
  39.  
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

systemgvp

  • New Member
  • *
  • Posts: 46
Re: Qt does not position forms
« Reply #13 on: May 12, 2026, 07:25:18 pm »
The problem is that I would like this solution to be already included in the application, and not have to start the app manually every time

In linux terminal: QT_QPA_PLATFORM=xcb ./yourapp , or if you run app via lazrus debugger, Run -> Run parameters -> click second tab "Environment", click Add button below, write env variable name QT_QPA_PLATFORM, for value set xcb, now run your qt6 app.

systemgvp

  • New Member
  • *
  • Posts: 46
Re: Qt does not position forms
« Reply #14 on: May 12, 2026, 07:35:53 pm »
As always when using AI things don't work, in fact lazarus doesn't recognize the fpGetEnv() and fpSetEnv() functions


Gemini propose this:

Code: Pascal  [Select][+][-]
  1. program YourAppName;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF LINUX}
  7.   Unix, // Required for fpGetEnv and fpSetEnv
  8.   {$ENDIF}
  9.   Interfaces, // Initializes the Lazarus widgetset
  10.   Forms,
  11.   Unit1;
  12.  
  13. {$IFDEF LINUX}
  14. procedure CheckAndForceXCB;
  15. var
  16.   SessionType: String;
  17. begin
  18.   // Retrieve the current desktop session type
  19.   SessionType := LowerCase(fpGetEnv('XDG_SESSION_TYPE'));
  20.  
  21.   // If running on Wayland, force Qt to fallback to XCB (via XWayland)
  22.   if SessionType = 'wayland' then
  23.   begin
  24.     fpSetEnv('QT_QPA_PLATFORM', 'xcb', 1);
  25.   end;
  26. end;
  27. {$ENDIF}
  28.  
  29. begin
  30.   {$IFDEF LINUX}
  31.   // This must execute before the Interfaces unit initializes Qt
  32.   CheckAndForceXCB;
  33.   {$ENDIF}
  34.  
  35.   Application.Initialize;
  36.   Application.CreateForm(TForm1, Form1);
  37.   Application.Run;
  38. end.
  39.  

 

TinyPortal © 2005-2018