1

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++.

BobMorane
  • 3,870
  • 3
  • 20
  • 42
  • By "not OK", do you mean that the space between the `Data1` and `Data2` labels is larger the second time (as if expanders had already been used)? Other than that, I see nothing strange here (Ubuntu, Gtkmm3 and g++) – BobMorane May 19 '21 at 20:12
  • 1
    Okay, I understand your problem. However, I am not able to reproduce it with the code your published. I click on the `Try this 2x` button once, then I see the expanders. I then click on `Back` and then `Try this 2x` again and the expanders are there. – BobMorane May 22 '21 at 13:18

1 Answers1

1

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

  • Please consider accepting your own answer if it solved your issue. This could help future users. Thanks! – BobMorane Aug 10 '21 at 00:24