GTK gossip: gtkprogressbar

Source: Internet
Author: User

Gtkprogressbar
You can use gtk_progress_bar_new () to create
Gtkprogressbar. To set the progress ratio, you can use the gtk_progress_bar_set_fraction () function. The value can be set to 0.0
1.0. You can use

Gtk_progress_bar_get_fraction.

You can use gtk_progress_bar_set_text () to set the text display.
Gtk_progress_bar_get_text (). You can also use
Gtk_progress_bar_set_orientation (): sets the moving direction of the import level column. The following values can be set:

  • Gtk_progress_left_to_right: left-to-right (reset)
  • Gtk_progress_right_to_left: Right to left
  • Gtk_progress_bottom_to_top: from bottom to top
  • Gtk_progress_top_to_bottom: from top to bottom

The following program uses gtk_timeout_add ()
Set a timer for the increase in the degree of Modulo progress:

  • Gtk_progress_bar_demo.c
#include <gtk/gtk.h>

gboolean timeout_callback(gpointer data) {
gdouble value;
GString *text;

value = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(data));

value += 0.01;
if(value > 1.0) {
value = 0.0;
}

gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), value);

text = g_string_new(
gtk_progress_bar_get_text(GTK_PROGRESS_BAR(data)));
g_string_sprintf(text, "%d %%", (int) (value * 100));

gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), text->str);

return TRUE;
}

int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *progressBar;
gint timer;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkProgressBar");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 30);

progressBar = gtk_progress_bar_new();
timer = gtk_timeout_add(100, timeout_callback, progressBar);

gtk_container_add(GTK_CONTAINER(window), progressBar);

g_signal_connect(GTK_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);

gtk_main();

return 0;
}

The results of the rows are as follows:




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.