如何在 gtkmm 中手动重绘树存储(扩展器不正确)?
How to redraw a treestore in gtkmm manually (expanders are not correct)?
我在 TreeStore/TreeView 中重新绘制扩展器时遇到问题。当我第一次调用 Example::Customize()
时,我可以看到扩展器。当我第二次调用 Example::Customize()
时,我看不到扩展器,直到我将鼠标光标移到 TreeStore/TreeView 上。刷新未完成
代码如下:
#include <gtkmm.h>
class Example : public Gtk::Window
{
public:
class RecordDefinition : public Gtk::TreeModel::ColumnRecord
{
public:
RecordDefinition() : Gtk::TreeModel::ColumnRecord()
{
add(Data1);
add(Data2);
};
~RecordDefinition(){};
Gtk::TreeModelColumn<Glib::ustring> Data1;
Gtk::TreeModelColumn<Glib::ustring> Data2;
};
RecordDefinition RD;
Example() : Gtk::Window(), TV(), refTS(), ButtonBack("Back")
{
set_position(Gtk::WIN_POS_CENTER);
set_default_size(600, 300);
Gtk::TreeIter itParent;
Gtk::TreeIter itChild;
refTS = Gtk::TreeStore::create(RD);
TV.set_model(refTS);
TV.append_column("Data1", RD.Data1);
TV.append_column("Data2", RD.Data2);
ButtonBack.signal_clicked().connect(sigc::mem_fun(*this,
&Example::ButtonBackClicked));
ButtonBack.show();
BoxMain.add(TV);
BoxMain.add(ButtonBack);
add(BoxMain);
show_all_children();
};
~Example(){};
Gtk::TreeView TV;
Glib::RefPtr<Gtk::TreeStore> refTS;
Gtk::VBox BoxMain;
Gtk::Button ButtonBack;
void ButtonBackClicked()
{
hide();
};
void Customize()
{
Gtk::TreeIter itParent;
Gtk::TreeIter itChild;
refTS->clear();
itParent = refTS->append();
(*itParent)[RD.Data1] = "Hello";
(*itParent)[RD.Data2] = "";
itChild = refTS->append((*itParent).children());
(*itChild)[RD.Data1] = "";
(*itChild)[RD.Data2] = "World";
itParent = refTS->append();
(*itParent)[RD.Data1] = "Mickey";
(*itParent)[RD.Data2] = "";
itChild = refTS->append((*itParent).children());
(*itChild)[RD.Data1] = "";
(*itChild)[RD.Data2] = "Mouse";
};
};
class ExampleWindow : public Gtk::Window
{
public:
ExampleWindow() : Gtk::Window(), BoxMain(),
Button("TRY THIS 2x!")
{
pE = NULL;
pE = new Example();
set_position(Gtk::WIN_POS_CENTER);
set_default_size(200, 100);
Button.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::ButtonClicked));
BoxMain.add(Button);
add(BoxMain);
show_all_children();
};
~ExampleWindow()
{
if (pE) delete pE;
};
Gtk::HBox BoxMain;
Gtk::Button Button;
void ButtonClicked()
{
pE->Customize();
pE->show();
};
Example *pE;
};
int main (int argc, char **argv)
{
int rc;
ExampleWindow *pEW;
auto App = Gtk::Application::create(argc, argv, "org.eli.de");
pEW = new ExampleWindow();
if (!pEW) exit(-1);
rc = App->run(*pEW);
if (pEW) delete pEW;
return(rc);
}
如何在第二次调用 Example::Customize()
时使 TreeStore/TreeView 正确刷新?
注意:我使用的是 openSUSE 15.2 / gtkmm 3.0 / g++。
这是KDE Plasma。我用 gnome 试过 openSUSE,没有问题。谢谢。
我在 TreeStore/TreeView 中重新绘制扩展器时遇到问题。当我第一次调用 Example::Customize()
时,我可以看到扩展器。当我第二次调用 Example::Customize()
时,我看不到扩展器,直到我将鼠标光标移到 TreeStore/TreeView 上。刷新未完成
代码如下:
#include <gtkmm.h>
class Example : public Gtk::Window
{
public:
class RecordDefinition : public Gtk::TreeModel::ColumnRecord
{
public:
RecordDefinition() : Gtk::TreeModel::ColumnRecord()
{
add(Data1);
add(Data2);
};
~RecordDefinition(){};
Gtk::TreeModelColumn<Glib::ustring> Data1;
Gtk::TreeModelColumn<Glib::ustring> Data2;
};
RecordDefinition RD;
Example() : Gtk::Window(), TV(), refTS(), ButtonBack("Back")
{
set_position(Gtk::WIN_POS_CENTER);
set_default_size(600, 300);
Gtk::TreeIter itParent;
Gtk::TreeIter itChild;
refTS = Gtk::TreeStore::create(RD);
TV.set_model(refTS);
TV.append_column("Data1", RD.Data1);
TV.append_column("Data2", RD.Data2);
ButtonBack.signal_clicked().connect(sigc::mem_fun(*this,
&Example::ButtonBackClicked));
ButtonBack.show();
BoxMain.add(TV);
BoxMain.add(ButtonBack);
add(BoxMain);
show_all_children();
};
~Example(){};
Gtk::TreeView TV;
Glib::RefPtr<Gtk::TreeStore> refTS;
Gtk::VBox BoxMain;
Gtk::Button ButtonBack;
void ButtonBackClicked()
{
hide();
};
void Customize()
{
Gtk::TreeIter itParent;
Gtk::TreeIter itChild;
refTS->clear();
itParent = refTS->append();
(*itParent)[RD.Data1] = "Hello";
(*itParent)[RD.Data2] = "";
itChild = refTS->append((*itParent).children());
(*itChild)[RD.Data1] = "";
(*itChild)[RD.Data2] = "World";
itParent = refTS->append();
(*itParent)[RD.Data1] = "Mickey";
(*itParent)[RD.Data2] = "";
itChild = refTS->append((*itParent).children());
(*itChild)[RD.Data1] = "";
(*itChild)[RD.Data2] = "Mouse";
};
};
class ExampleWindow : public Gtk::Window
{
public:
ExampleWindow() : Gtk::Window(), BoxMain(),
Button("TRY THIS 2x!")
{
pE = NULL;
pE = new Example();
set_position(Gtk::WIN_POS_CENTER);
set_default_size(200, 100);
Button.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::ButtonClicked));
BoxMain.add(Button);
add(BoxMain);
show_all_children();
};
~ExampleWindow()
{
if (pE) delete pE;
};
Gtk::HBox BoxMain;
Gtk::Button Button;
void ButtonClicked()
{
pE->Customize();
pE->show();
};
Example *pE;
};
int main (int argc, char **argv)
{
int rc;
ExampleWindow *pEW;
auto App = Gtk::Application::create(argc, argv, "org.eli.de");
pEW = new ExampleWindow();
if (!pEW) exit(-1);
rc = App->run(*pEW);
if (pEW) delete pEW;
return(rc);
}
如何在第二次调用 Example::Customize()
时使 TreeStore/TreeView 正确刷新?
注意:我使用的是 openSUSE 15.2 / gtkmm 3.0 / g++。
这是KDE Plasma。我用 gnome 试过 openSUSE,没有问题。谢谢。