Recent

Author Topic: [SOLVED] Autosize - How to know size before show?  (Read 9031 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1057
[SOLVED] Autosize - How to know size before show?
« on: February 18, 2011, 12:32:29 am »
Hi,

I have problem with autosize. I am reading documentation of this property but can't find solution. I have this situtation (this is only example, in my form is more controls with autosize):

Form1.Autosize = True;
Label1.AutoSize = True;
Label1.Align = alTop;

When I change caption in Label1, form width is "fit" to this size. This is ok, but new form width is calculated only when I make it visible. How do I know final form width before show?

Regards.
« Last Edit: February 18, 2011, 03:57:20 pm by Dibo »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Autosize - How to know size before show?
« Reply #1 on: February 18, 2011, 01:27:10 am »
I made a few experimetns and I have no idea how to do it in convenient way.  :(

Only thing that work for me is this crazy method:

Code: [Select]
  Form2.Show;
  Form2.Close;
  Caption:=inttostr(Form2.Width);    //now it has final size   

Show and Close is sooooo fast .....   :D
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: Autosize - How to know size before show?
« Reply #2 on: February 18, 2011, 02:17:18 am »
it's somewhere on the wiki.

forms autosize only ONCE.

To autosize a form a 2nd time, set Form.Autosize to False, and then back to true again.

You must do this, each time you need the autosize.
---

The reason: under Linux some Windowmanager do interfere with autosize... search the wiki, read the full story there

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Autosize - How to know size before show?
« Reply #3 on: February 18, 2011, 02:51:40 am »
http://wiki.lazarus.freepascal.org/Autosize_/_Layout#AutoSize_and_Forms

But seems not work for invisible forms at least here on Qt.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

zeljko

  • Hero Member
  • *****
  • Posts: 1751
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Autosize - How to know size before show?
« Reply #4 on: February 18, 2011, 12:19:44 pm »
I don't use autosize for forms, but again,don't understand what does not work with qt ? afaik, it does not matter if form is visible or not. Open an issue about it and attach example.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Autosize - How to know size before show?
« Reply #5 on: February 18, 2011, 12:52:07 pm »
OK. I opened issue http://bugs.freepascal.org/view.php?id=18775. When you say that invisible forms should be resized than it is probably bug.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Autosize - How to know size before show?
« Reply #6 on: February 18, 2011, 01:56:32 pm »
it's somewhere on the wiki.

forms autosize only ONCE.

To autosize a form a 2nd time, set Form.Autosize to False, and then back to true again.

You must do this, each time you need the autosize.

This doesn't work on linux (GTK). I try read more about this

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Autosize - How to know size before show?
« Reply #7 on: February 18, 2011, 03:57:05 pm »
@Blaazen. Mattias Gaertner post nice trick in your issue. This code solve my problem and return me final form width without showing it:

Form1.HandleNeeded;
Form1.GetPreferredSize(W,H);

 

TinyPortal © 2005-2018