Formatted Text in Gtk::TreeView

Discussion in 'Ruby' started by Michael Gebhart, Feb 27, 2005.

  1. Hi,

    I wanna have some formatted text in my treeview. The problem is: I wanna
    have different formats in one cell, that means:

    I have one cell. In this cell, there are 3 lines of text. The first line
    has to be bold, the second one grey colored, and the third one underlined.

    I've read the tutorial about the treeview and I know, that I have to use
    the cellrenderer. But now I only can set the format for the whole cell,
    not for each line different.

    Any ideas, how to do this?

    Greetings

    Michael
     
    Michael Gebhart, Feb 27, 2005
    #1
    1. Advertising

  2. Michael Gebhart

    Masao Mutoh Guest

    Hi,

    On Sun, 27 Feb 2005 19:49:58 +0900
    Michael Gebhart <> wrote:

    > Hi,
    >
    > I wanna have some formatted text in my treeview. The problem is: I wanna
    > have different formats in one cell, that means:
    >
    > I have one cell. In this cell, there are 3 lines of text. The first line
    > has to be bold, the second one grey colored, and the third one underlined.
    >
    > I've read the tutorial about the treeview and I know, that I have to use
    > the cellrenderer. But now I only can set the format for the whole cell,
    > not for each line different.
    >
    > Any ideas, how to do this?


    Use Gtk::CellRendererText#markup=.

    Pango Text Attribute Markup Language is similer HTML/CSS and you can
    apply it to Gtk::Widgets which have #markup= method.

    http://developer.gnome.org/doc/API/2.0/pango/PangoMarkupFormat.html

    ---------------------------------------
    require 'gtk2'

    Gtk.init

    model = Gtk::TreeStore.new(String)
    tv = Gtk::TreeView.new(model)

    cell = Gtk::CellRendererText.new
    column = Gtk::TreeViewColumn.new("Title", cell, :markup => 0)
    tv.append_column(column)

    msg = %Q[
    <b>bold</b>
    <span foreground="#dddddd">Grey colored</span>
    <u>Underlined</u>
    ]

    2.times do
    iter = model.append(nil)
    model.set_value(iter, 0, msg)
    end

    window = Gtk::Window.new.add(tv).set_default_size(300,300).show_all

    --
    :% Masao Mutoh<>
     
    Masao Mutoh, Feb 27, 2005
    #2
    1. Advertising

  3. Yeah great, thanks!!

    Michael
     
    Michael Gebhart, Feb 27, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. manatlan
    Replies:
    0
    Views:
    449
    manatlan
    Apr 25, 2005
  2. Replies:
    2
    Views:
    545
  3. Replies:
    0
    Views:
    391
  4. Gergely Kontra
    Replies:
    2
    Views:
    271
    Joao Pedrosa
    Jun 18, 2004
  5. Alex Shulgin
    Replies:
    1
    Views:
    194
    thefed
    Nov 21, 2007
Loading...

Share This Page