Lazarus

Programming => LCL => Topic started by: senglit on May 31, 2020, 08:30:25 pm

Title: Very serious flicker when StringGrids on PageControl
Post by: senglit on May 31, 2020, 08:30:25 pm
Hi all,

I have a TPageControl on my main form. It includes 5 TabSheets. In each TabSheet, there is a second level PageControl which have 3 to 5 TabSheets. In many of the sencond level TabSheet there is 1 TStringGrid.

I set the color of main form to clBlack, and set all of the color of StringGrids to clBlack.

There is a very serious flicker when I switch from one TabSheet to another. the canvas of StringGrid first is white, then it changes into black as I designed. It makes my application seems very silly.

I checked the property of StringGrids and ensured the DoubleBuffer are default as True. According to my knowledge, it should reduce the flicker very well. But it seems not working.

What should I do to avoid the flicker?

Thanks.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: jamie on June 01, 2020, 12:32:57 am
You could try
on the PageControl

PageControl.BeginBoundsUpdate;

then switch your forms..
and
go back to it.
PageControl.EndBoundsUpdate;

Like I said don't know if it will work for you..

Also, if you are repositioning items this is going to repaint lots of windows.

and in many cases you don't want to call Repaint because that is a direct route, call Update or invalidate at some point. that puts a delayed paint message in the que..
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: wp on June 01, 2020, 12:45:51 am
@senglit: Please post a zipped project so that we can see the issue ourselves. You should simplify your project as much as possible, but the flicker should remain, of course. Put the .pas, .lfm, .lpi and .lpr files into a common .zip which you can upload via "Attachements and other options" below the forum editor box. Do not include .exe, .ppu, .o, .res and other compiler-generated files, they are not needed and may make the upload exceed the file size limit of 250 KB.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: Martin_fr on June 01, 2020, 01:33:14 am
If I recall correctly, then the same can be seen when switching SourceEditors in the IDE (assuming dark background).

Also from memory, I think the problem is, that switching pages, means
1) hiding the current page
2) showing the new page

In between the page control is painted without any page. And that is the white surface you see as flicker.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: senglit on June 01, 2020, 06:13:07 am
@senglit: Please post a zipped project so that we can see the issue ourselves.

Hi wp, there is a demo to show the flicker.

Some normal components are used, such as TEdit, TLabel, TStringGrid, TFloatSpinEdit, TPageControl and TTabSheet. All of the components are set as: backcolor->black, fontcolor->white.

The demo will do nothing but just show the components, and the flicker is serious now.

BTW: I use win10. I searched the forum and saw people said it's no way to change the backcolor,tablecolor,margincolor of TPageControl. That is a bad news to me. I don't want to see a white space between my level 1 pagecontrol and level 2 pagecontrol. Do you have a solution?
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: senglit on June 01, 2020, 06:22:36 am
You could try
on the PageControl

PageControl.BeginBoundsUpdate;

then switch your forms..
and
go back to it.
PageControl.EndBoundsUpdate;

Like I said don't know if it will work for you..

Also, if you are repositioning items this is going to repaint lots of windows.

and in many cases you don't want to call Repaint because that is a direct route, call Update or invalidate at some point. that puts a delayed paint message in the que..

I'm not sure if I understand you correctly. For a certain TableSheet which has a StringGrid child, I added "TabSheet.BeginUpdateBounds;" in the OnEnter event and "TabSheet.EndUpdateBounds" in the OnExit event. But the flicker is still there.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: WooBean on June 01, 2020, 08:03:44 am
I tried your project (tmp4) in Windows 7/64, FPC 3.0.4, Lazarus 2.0.8 - nothing special at changing tabs - no flickering seen.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: trev on June 01, 2020, 08:41:46 am
I tried your project (tmp4) in macOS 10.14.6, FPC 3.0.4, Lazarus 2.0.6 - switched between all tabs and back again - no flickering to be seen at all.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: senglit on June 01, 2020, 08:47:18 am
TO WooBean & trev,

It's strange. I don't have WIN7/64 nor macOs with me, but I tried it on 3 computers (all of them are win10), and flicker show on every one.

Is it a Win10-Only problem?
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: TraumTaenzerDieter on June 01, 2020, 09:03:55 am
Not only on Win10: it also flickers on Win7/64!
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: trev on June 01, 2020, 09:29:48 am
Video drivers?
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: balazsszekely on June 01, 2020, 09:39:17 am
The flicker is clearly visible on slower machines. @Martin_fr explained what causes the issue. I attach a windows only, pseudo solution, which will work, but the flickering should be fixed in LCL.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: BrunoK on June 01, 2020, 02:33:48 pm
A possible patch that should prevent WM_ERASEBACKGROUND when a tab becomes inactive.

Lazarus quite recent trunk (+/- changes regarding TScrollBar, IntitalSetupDialog, Options.Environment options).  FPC 3.0.4 (the mac os one) from svn + some mods.
Windows 10 Pro x64 (v. 1903 / 18362.418) and for occasional Linux tests, Manjaro (QT5 and GTK2)

Title: Re: Very serious flicker when StringGrids on PageControl
Post by: Martin_fr on June 01, 2020, 03:06:27 pm
Please put the patch on the bugtracker.
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: jamie on June 01, 2020, 03:38:55 pm
I just did one differently using the Lock windows in the Select Change message handler and it works perfectly...

 Absolutely no flicker at all.

it did it in the TabcontrolParentMsghandler.

That sections receives both the Changing and changed messages..
I can forward a message to anyone that is interested... or put my suggestion in the bug tracker.


 I do like the other suggestion too, might be less of a chance of window locking

EDIT:

 Just tried that, yes that works just as well as the lock does with less risk!
 
 Please summit Thank you.
 :)
Title: Re: Very serious flicker when StringGrids on PageControl
Post by: senglit on June 01, 2020, 06:23:19 pm
Martin_fr is right, the flicker can be seen during the designed time in the IDE.

Thanks to GetMem and BrunoK for your solutions, both work. Thanks to jamie, please contribute your suggestion in the bug tracker.

It seems Only TPageControl gets this problem. I built a self-made version TPageControl which composed of TImage and TPanel. And there is no flicker problem.
TinyPortal © 2005-2018