Messages

A message is a type of dialog window that is used to notify the user about some action or state change; they can also be used to pose a question or ask for user confirmation.

GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT
                     | GTK_DIALOG_MODAL;

// "parent_window" is defined elsewhere
GtkWidget *dialog =
  gtk_message_dialog_new (parent_window,
                          flags,
                          GTK_MESSAGE_ERROR,
                          GTK_BUTTONS_CLOSE,
                          "Error reading “%s”",
                          // "filename" is defined elsewhere
                          filename);

// Destroy the dialog when the user responds to it
g_signal_connect (dialog, "response",
                  G_CALLBACK (gtk_window_destroy),
                  NULL);

Useful methods for the component

  • If your message contains Pango markup you can set the GtkMessageDialog:use-markup property to true.

  • A message dialog can also contain a secondary text, which is displayed underneath the message specified in the GtkMessageDialog:text property. You can use the GtkMessageDialog:secondary-text property to define the secondary text.

  • The secondary text can also use Pango markup, as long as you set the GtkMessageDialog:secondary-use-markup to true.

API references

In the examples we used the following classes: