Formatted Text in Gtk::TreeView

M

Michael Gebhart

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
 
M

Masao Mutoh

Hi,

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top