gtk(mm) 3 锚定在文本视图中的文本视图无法将光标放入内部
gtk(mm) 3 text view anchored in text view cannot get cursor inside
问题只发生在为 GTK3 构建时;为 GTK2 构建相同的代码工作正常。
在下面的代码中,我将一个文本视图锚定到另一个文本视图中。问题是,即使我单击鼠标,我也无法让光标在嵌套文本视图内移动以写入文本。光标可以轻松进入正下方的文本条目。
// g++ codebox.cc -o codebox `pkg-config gtkmm-3.0 --cflags --libs`
// g++ codebox.cc -o codebox `pkg-config gtkmm-2.4 --cflags --libs`
#include <iostream>
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
window.set_default_size(450, 450);
Gtk::TextView textViewBase;
Glib::RefPtr<Gtk::TextBuffer> rBufferBase = textViewBase.get_buffer();
Gtk::TextView textViewNested;
Gtk::ScrolledWindow scrolledWindowNested;
scrolledWindowNested.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
scrolledWindowNested.add(textViewNested);
scrolledWindowNested.set_size_request(300, 300);
Gtk::Entry entryNested;
rBufferBase->insert(rBufferBase->end(), "Anchored TextView below:\n==>");
Glib::RefPtr<Gtk::TextChildAnchor> rAnchorTextView = rBufferBase->create_child_anchor(rBufferBase->end());
rBufferBase->insert(rBufferBase->end(), "<==\nAnchored TextView above^\n\nAnchored Entry below:\n==>");
Glib::RefPtr<Gtk::TextChildAnchor> rAnchorEntry = rBufferBase->create_child_anchor(rBufferBase->end());
rBufferBase->insert(rBufferBase->end(), "<==\nAnchored Entry above^\n");
textViewBase.add_child_at_anchor(scrolledWindowNested, rAnchorTextView);
scrolledWindowNested.show_all();
textViewBase.add_child_at_anchor(entryNested, rAnchorEntry);
entryNested.show_all();
window.add(textViewBase);
window.show_all();
Gtk::Main::run(window);
return EXIT_SUCCESS;
}
在嵌套文本视图中,停止 signal_button_press_event(鼠标)到达下面的基本文本视图就可以了:
textViewNested.signal_button_press_event().connect([](GdkEventButton* pEvent){ return true; });
问题只发生在为 GTK3 构建时;为 GTK2 构建相同的代码工作正常。
在下面的代码中,我将一个文本视图锚定到另一个文本视图中。问题是,即使我单击鼠标,我也无法让光标在嵌套文本视图内移动以写入文本。光标可以轻松进入正下方的文本条目。
// g++ codebox.cc -o codebox `pkg-config gtkmm-3.0 --cflags --libs`
// g++ codebox.cc -o codebox `pkg-config gtkmm-2.4 --cflags --libs`
#include <iostream>
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
window.set_default_size(450, 450);
Gtk::TextView textViewBase;
Glib::RefPtr<Gtk::TextBuffer> rBufferBase = textViewBase.get_buffer();
Gtk::TextView textViewNested;
Gtk::ScrolledWindow scrolledWindowNested;
scrolledWindowNested.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
scrolledWindowNested.add(textViewNested);
scrolledWindowNested.set_size_request(300, 300);
Gtk::Entry entryNested;
rBufferBase->insert(rBufferBase->end(), "Anchored TextView below:\n==>");
Glib::RefPtr<Gtk::TextChildAnchor> rAnchorTextView = rBufferBase->create_child_anchor(rBufferBase->end());
rBufferBase->insert(rBufferBase->end(), "<==\nAnchored TextView above^\n\nAnchored Entry below:\n==>");
Glib::RefPtr<Gtk::TextChildAnchor> rAnchorEntry = rBufferBase->create_child_anchor(rBufferBase->end());
rBufferBase->insert(rBufferBase->end(), "<==\nAnchored Entry above^\n");
textViewBase.add_child_at_anchor(scrolledWindowNested, rAnchorTextView);
scrolledWindowNested.show_all();
textViewBase.add_child_at_anchor(entryNested, rAnchorEntry);
entryNested.show_all();
window.add(textViewBase);
window.show_all();
Gtk::Main::run(window);
return EXIT_SUCCESS;
}
在嵌套文本视图中,停止 signal_button_press_event(鼠标)到达下面的基本文本视图就可以了:
textViewNested.signal_button_press_event().connect([](GdkEventButton* pEvent){ return true; });