⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-scalewidgets.html

📁 gtk的教材和问答集
💻 HTML
字号:
<HTML><HEAD><TITLE>Scale Widgets</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Range Widgets"HREF="ch-rangewidgets.html"><LINKREL="PREVIOUS"TITLE="Range Widgets"HREF="ch-rangewidgets.html"><LINKREL="NEXT"TITLE="Common Range Functions"HREF="sec-commonrangefunctions.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="ch-rangewidgets.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 8. Range Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-commonrangefunctions.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-SCALEWIDGETS">8.2. Scale Widgets</A></H1><P>Scale widgets are used to allow the user to visually select andmanipulate a value within a specific range. You might want to use ascale widget, for example, to adjust the magnification level on azoomed preview of a picture, or to control the brightness of a color,or to specify the number of minutes of inactivity before a screensavertakes over the screen.</P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN592">8.2.1. Creating a Scale Widget</A></H2><P>As with scrollbars, there are separate widget types for horizontal andvertical scale widgets. (Most programmers seem to favour horizontalscale widgets.) Since they work essentially the same way, there's noneed to treat them separately here. The following functions, definedin <TTCLASS="LITERAL">&#60;gtk/gtkvscale.h&#62;</TT> and<TTCLASS="LITERAL">&#60;gtk/gtkhscale.h&#62;</TT>, create vertical and horizontal scalewidgets, respectively:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_vscale_new( GtkAdjustment *adjustment );GtkWidget *gtk_hscale_new( GtkAdjustment *adjustment );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">adjustment</TT> argument can either be an adjustment which hasalready been created with <TTCLASS="LITERAL">gtk_adjustment_new()</TT>, or <TTCLASS="LITERAL">NULL</TT>, inwhich case, an anonymous Adjustment is created with all of itsvalues set to <TTCLASS="LITERAL">0.0</TT> (which isn't very useful in this case). Inorder to avoid confusing yourself, you probably want to create youradjustment with a <TTCLASS="LITERAL">page_size</TT> of <TTCLASS="LITERAL">0.0</TT> so that its <TTCLASS="LITERAL">upper</TT>value actually corresponds to the highest value the user can select.(If you're <ICLASS="EMPHASIS">already</I> thoroughly confused, read the section on <AHREF="ch-adjustments.html">Adjustments</A> again for an explanation ofwhat exactly adjustments do and how to create and manipulate them.)</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN608">8.2.2. Functions and Signals (well, functions, at least)</A></H2><P>Scale widgets can display their current value as a number beside thetrough. The default behaviour is to show the value, but you can changethis with this function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_scale_set_draw_value( GtkScale *scale,                               gint      draw_value );</PRE></TD></TR></TABLE><P>As you might have guessed, <TTCLASS="LITERAL">draw_value</TT> is either <TTCLASS="LITERAL">TRUE</TT> or<TTCLASS="LITERAL">FALSE</TT>, with predictable consequences for either one.</P><P>The value displayed by a scale widget is rounded to one decimal pointby default, as is the <TTCLASS="LITERAL">value</TT> field in its GtkAdjustment. You canchange this with:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_scale_set_digits( GtkScale *scale,                            gint     digits );</PRE></TD></TR></TABLE><P>where <TTCLASS="LITERAL">digits</TT> is the number of decimal places you want. You canset <TTCLASS="LITERAL">digits</TT> to anything you like, but no more than 13 decimalplaces will actually be drawn on screen.</P><P>Finally, the value can be drawn in different positionsrelative to the trough:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_scale_set_value_pos( GtkScale        *scale,                              GtkPositionType  pos );</PRE></TD></TR></TABLE><P>The argument <TTCLASS="LITERAL">pos</TT> is of type <TTCLASS="LITERAL">GtkPositionType</TT>, which isdefined in <TTCLASS="LITERAL">&#60;gtk/gtkenums.h&#62;</TT>, and can take one of thefollowing values:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  GTK_POS_LEFT  GTK_POS_RIGHT  GTK_POS_TOP  GTK_POS_BOTTOM</PRE></TD></TR></TABLE><P>If you position the value on the "side" of the trough (e.g., on thetop or bottom of a horizontal scale widget), then it will follow theslider up and down the trough.</P><P>All the preceding functions are defined in<TTCLASS="LITERAL">&#60;gtk/gtkscale.h&#62;</TT>. The header files for all GTK widgetsare automatically included when you include<TTCLASS="LITERAL">&#60;gtk/gtk.h&#62;</TT>. But you should look over the header filesof all widgets that interest you,</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="ch-rangewidgets.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-commonrangefunctions.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Range Widgets</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-rangewidgets.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Common Range Functions</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -