0
votes

I am having a weird problem using Gtk3 in C:

I have a GTKTreeView of 2 columns (Both TEXT) on which I add (dynamically) a single row :
The second column on that row is 'Editable' (Using glade).
I can double-click on the Cell, which triggers the EDIT MODE : Background becomes white, and a cursor appears.
However, I cannot type into the CELL using the keyboard: the mouse seems to work though (I can paste into the cell without a problem).

The TreeView itself has the 'CAN_FOCUS' Flag turned on.
What am I missing here ?

1

1 Answers

0
votes

The following is a small program which does what you describe (you should really post a small example code which exhibits your problem!). I'm sorry - it's in Python - but it should be similar enough for you. Note:

  • can_focus has no effect here (in fact, it's probably on by default)
  • you have to enable the correct renderer's 'editable' (which I believe you did)
  • you have to connect a handler to the renderer's 'edited' signal, and take care of updating the store yourself.

Listing:

from gi.repository import Gtk

class MainWindow(Gtk.Window):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.set_size_request(150, 60)
        self.connect("destroy", lambda x: Gtk.main_quit())

        store = Gtk.ListStore(str, str)
        view = Gtk.TreeView(model = store)

        for i, hdr in enumerate(("Col1", "Col2")):
            if i == 1:
                renderer = Gtk.CellRendererText(editable = True)
                renderer.connect("edited", self.on_edited)
            else:
                renderer = Gtk.CellRendererText()
            col = Gtk.TreeViewColumn(hdr, renderer, text = i)
            view.append_column(col)

        store.append(("One", "Two"))

        self.add(view)
        self.show_all()

    def on_edited(self, renderer, path, new_text):
        print(" Modify the store here [edited text:  %s]" % new_text)


    def run(self):
        Gtk.main()

def main(args):
    mainwdw = MainWindow()
    mainwdw.run()

    return 0

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

Initial window:

Initial window

Click on col2:

Click on col2

Edited:

Edited

Print from handler:

Output from handler