gtkmmexpanderredrawtreestore

How to redraw a treestore in gtkmm manually (expanders are not correct)?


I have problems with the redrawing of expanders in a TreeStore/TreeView. When I call Example::Customize() for the first time, I can see the expanders. When I call Example::Customize() for the second time, I can see no expanders until I move the mouse cursor over the TreeStore/TreeView. The refreshing is not complete.

Here is the code:

#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);
}

How can I make the TreeStore/TreeView refresh correctly on the second call to Example::Customize()?

Note: I am using openSUSE 15.2 / gtkmm 3.0 / g++.


Solution

  • It is the KDE Plasma. I tried openSUSE with gnome and there was no problem. Thanks.