Entry
Enkel användning
Entry widgets allow the user to enter text. You can change the contents with the set_text() method, and read the current contents with the get_text() method.
Ibland kan du vilja göra en Entry-komponent skrivskyddad. Detta kan göras genom att skicka false till metoden set_editable().
För inmatning av lösenord, lösenfraser och annan information du inte vill ska skrivas ut på skärmen kan du anropa set_visibility() med false för att texten ska vara dold.
You might want to be notified whenever the user types in a text entry widget. Gtk::Entry provides two signals, activate (since gtkmm 4.8) and changed, for this purpose. activate is emitted when the user presses the Enter key in a text-entry widget; changed is emitted when the text in the widget changes. You can use these, for instance, to validate or filter the text the user types. Moving the keyboard focus to another widget may also signal that the user has finished entering text. The leave signal in a Gtk::EventControllerFocus can notify you when that happens. The ComboBox with an Entry section contains example programs that use these signals.
If you pass true to the set_activates_default() method, pressing Enter in the Gtk::Entry will activate the default widget for the window containing the Gtk::Entry. This is especially useful in dialog boxes. The default widget is usually one of the dialog buttons, which e.g. will close the dialog box. To set a widget as the default widget, use Gtk::Window::set_default_widget().
Simple Entry Example
Detta exempel använder Gtk::Entry. Det har också två CheckButton-knappar, med vilka du kan växla flaggorna för redigering och synlighet.
Entry Completion
Gtk::EntryCompletion är föråldrad sedan gtkmm 4.10. Det finns ingen ersättning i gtkmm.
En Entry-komponent kan erbjuda en rullgardinslista med befintliga val baserat på de första tecken som användaren skrivit in. En sökdialog skulle exempelvis kunna föreslå text från tidigare sökningar.
För att aktivera denna funktionalitet måste du skapa ett EntryCompletion-objekt, och tillhandahålla det till Entry-komponenten genom metoden set_completion().
The EntryCompletion may use a TreeModel containing possible entries, specified with set_model(). You should then call set_text_column() to specify which of your model columns should be used to match possible text entries.
Alternatively, if a complete list of possible entries would be too large or too inconvenient to generate, a callback slot may instead be specified with set_match_func(). This is also useful if you wish to match on a part of the string other than the start.
Entry Completion Example
Detta exempel skapar en Gtk::EntryCompletion och associerar den med en Gtk::Entry-komponent. Kompletteringen använder en Gtk::TreeModel med möjliga inmatningar och några ytterligare åtgärder.
Entry Icons
En Entry-komponent kan visa en ikon i början eller i slutet på textområdet. Ikonen kan anges av metoder som set_icon_from_paintable() eller set_icon_from_icon_name(). Ett program kan svara på tryck på ikonen genom att hantera signalen signal_icon_press.
Entry Icon Example
Detta exempel visar en Gtk::Entry-komponent med en namngiven sökikon, och skriver ut text till terminalen när ikonen trycks ned.
Entry Progress
En Entry-komponent kan visa en förloppsindikator inuti textområdet, under den inmatade texten. Förloppsindikatorn kommer visas om metoderna set_progress_fraction() eller set_progress_pulse_step() anropas.
Entry Progress Example
Detta exempel visar en Gtk::Entry-komponent med en förloppsindikator.