Sign in Join

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

Mailing lists / lazarus / 2015-01

Gtk3 - Set entry placeholder

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Krzysztof

Hi,

I'm testing Gtk3 (I know that it is in alpha stage). I have latest lazarus from svn (1.3)

When using low level Gtk3 api then this code work fine:

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  LazGtk3, LazGObject2;
{$R *.res}
var
  window: PGtkWindow;
  entry1, entry2: PGtkWidget;
  vbox: PGtkWidget;
begin
  gtk_init (@argc, @argv);
  window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (window, 'Window');
  g_signal_connect_data(window, 'destroy', TGCallback(@gtk_main_quit), nil,
nil, 0);
  vbox := gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
  gtk_container_add (PGtkContainer(window), vbox);
  entry1 := gtk_entry_new ();
  gtk_entry_set_text(PGtkEntry(entry1), 'Hello');
  entry2 := gtk_entry_new ();
  gtk_entry_set_placeholder_text(PGtkEntry(entry2), '<Test>');
  gtk_box_pack_start(PGtkBox(vbox), entry1, True, True, 0);
  gtk_box_pack_start(PGtkBox(vbox), entry2, True, True, 0);
  gtk_widget_show_all (window);
  gtk_main ();
end.

But if I create LCL application, then change LCLWidgetType to Gtk3 and call this:

procedure TForm1.Button1Click(Sender: TObject);
begin
  gtk_entry_set_placeholder_text(Edit1.Handle), PChar('Test'));
end;

Then it doesn't work. Edit1.Handle should point to gtk widget right? -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150105/2312d7ee/attachment.html>

Reply by email

zeljko
to Krzysztof
Krzysztof wrote 53 lines
Hi, I'm testing Gtk3 (I know that it is in alpha stage). I have latest lazarus from svn (1.3) When using low level Gtk3 api then this code work fine: uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset LazGtk3, LazGObject2; {$R *.res} var window: PGtkWindow; entry1, entry2: PGtkWidget; vbox: PGtkWidget; begin gtk_init (@argc, @argv); window := gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (window, 'Window'); g_signal_connect_data(window, 'destroy', TGCallback(@gtk_main_quit), nil, nil, 0); vbox := gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (PGtkContainer(window), vbox); entry1 := gtk_entry_new (); gtk_entry_set_text(PGtkEntry(entry1), 'Hello'); entry2 := gtk_entry_new (); gtk_entry_set_placeholder_text(PGtkEntry(entry2), '<Test>'); gtk_box_pack_start(PGtkBox(vbox), entry1, True, True, 0); gtk_box_pack_start(PGtkBox(vbox), entry2, True, True, 0); gtk_widget_show_all (window); gtk_main (); end. But if I create LCL application, then change LCLWidgetType to Gtk3 and call this: procedure TForm1.Button1Click(Sender: TObject); begin gtk_entry_set_placeholder_text(Edit1.Handle), PChar('Test'));
That's because Edit1.Handle is not PGtkEntry, but TGtk3Entry, so this
code should work (you must include gtk3widgets unit to get it work):
gtk_entry_set_placeholder_text(PGtkEntry(TGtk3Edit(Edit1.Handle).Widget), PChar('Test'));
or
var
   AEntry: PGtkEntry;
begin
   AEntry := PGtkEntry(TGtk3Edit(Edit1.Handle).Widget);
   gtk_entry_set_placeholder_text(AEntry, PChar('Test'));
end;

zeljko

Reply by email