Sign in Join

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

Mailing lists / qt / 2007-06

Modal windows proposal

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

zeljko

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;

Reply by email