[Qt] Modal windows proposal

zeljko zeljko at holobit.net
Sat Jun 23 14:12:29 CEST 2007


Hi,

I've played a bit around and think that nice solution is founded, much 
better than current one with Hide() Show().
Why is this better:
1.No flicking when ShowModal() is called (because of Hide() Show() calls)
2.No flicking when click some other form while modal form is shown.
3.No problems when minimizing-restoring main application form while modal form 
is visible.

Modified showModal() is here :

class procedure TQtWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
var
  ADialog: TQtDialog;
  R: TRect;
  Str: WideString;
  Icon: QIconH;
  AParent: QWidgetH;
begin
  {$ifdef VerboseQt}
    WriteLn('Trace:> [TQtWSCustomForm.ShowModal]');
  {$endif}

  if Assigned(ACustomForm.Parent) then
  ADialog := TQtDialog.Create(TQtMainWindow(ACustomForm.Parent.Handle).Widget, 
QtDialog)
  else
  ADialog := TQtDialog.Create(NiL, QtDialog);
  
  QWidget_setFocusPolicy(ADialog.Widget, QtNoFocus);

  Str := UTF8Encode(ACustomForm.Caption);
  QWidget_setWindowTitle(ADialog.Widget, @Str);
  
  Icon := QIcon_create;
  try
  QWidget_windowIcon(TQtWidget(ACustomForm.Handle).Widget, Icon);
  QWidget_setWindowIcon(ADialog.Widget, Icon);
  finally
  QIcon_destroy(Icon);
  end;
  
  QWidget_geometry(TQtWidget(ACustomForm.Handle).Widget, @R);
  QWidget_setGeometry(ADialog.Widget, @R);
  try
  AParent := QWidget_parentWidget(TQtWidget(ACustomForm.Handle).Widget);
  
  TQtWidget(ACustomForm.Handle).setParent(ADialog.Widget);

  QWidget_move(TQtWidget(ACustomForm.Handle).Widget, 0, 0);
  
  QWidget_setFocusProxy(TQtWidget(ACustomForm.Handle).Widget, ADialog.Widget);
  
//  TQtWidget(ACustomForm.Handle).Show;
//  TQtWidget(ACustomForm.Handle).setWindowModality(QtApplicationModal);
//  TQtWidget(ACustomForm.Handle).Show;

  ACustomForm.ModalResult := TModalResult(ADialog.exec);

  TQtWidget(ACustomForm.Handle).setParent(AParent);
  ACustomForm.Hide;
  
  Application.ProcessMessages;
  sleep(10);
  Application.ProcessMessages;
  
  finally
  ADialog.Free;
  end;


  {BUG: if we assign OnCloseQuery(), Lazarus TCustomForm.Close() Fires 
ModalResult = mrCancel,
    without counting on OnCloseQuery() result (CanClose), so if we set it up 
we'll jump over our
   loop, and then comes into LCL loop with WidgetSet.AppProcessMessages
   which burns CPU ...}
   
  {$ifdef VerboseQt}
    WriteLn('Trace:< [TQtWSCustomForm.ShowModal]');
  {$endif}
end;                                  



More information about the Qt mailing list