Re: combo box in dialog did not work, not mouse selctable, lots of Gdk-CRITICAL messages on console output



Well, first of all: Your code runs perfectly for me. I compiled it with:

        g++ main.cpp `pkg-config --cflags --libs gtkmm-3.0` -std=c++11

Which platform do you run on, and could it be that you don't use the
default Gtk+ theme you had there in the beginning? IIRC I had similar
problems with outdated Gtk+ themes (that were made for older Gtk+ versions).

Also, just some quick notes about the code from your email:

* Please don't use non-english identifiers. I would say in any code you
write, but just following this for situations in which you communicate
with people whose common language is English, like on this mailing list,
that would be an improvement.

* Bear in mind that Gtk::Stock is deprecated, especially if you're
writing new code

* What goes for identifiers in the code also goes for strings: Please
write them in English. Of course this was a trivial example which most
or all people on here understand after a quick read through even if they
don't speak German, but this program seems like an example you created
for this mailing list, so why do it in German? (for production code,
have a look at the gtkmm tutorial chapter 27 [1] about i18n and l10n, if
you haven't already)

[1]
https://developer.gnome.org/gtkmm-tutorial/stable/chapter-internationalization.html.en

Am 18.02.2015 um 13:29 schrieb Klaus Rudolph:
Hi again,

I tried to get a combo box to work in a dialog window. But the behavior is strange. The following things 
will not work:

After the dialog window opens ( after pressing the do button in my example code ) you can open the combo 
box list with a mouse click. But it is not possible to select an item in the list with the mouse! If you 
change the selected entry with the space bar and cursor the console gives an endless list of messages:
"(go:9768): Gdk-CRITICAL **: gdk_window_get_device_position_double: assertion 'GDK_IS_DEVICE (device)' 
failed"

If I add my combo box to the main window it seems to work normally. Maybe the code is broken in general, 
but if the combo box runs from main window I can no see any misbehavior.

The following code is complete to compile and run.

#include <iostream>
#include <gtkmm.h>
#include <vector>
using namespace std;

Gtk::Window* winptr;

class MyComboBox: public Gtk::ComboBox
{   
    private:
        class ModelColumns : public Gtk::TreeModel::ColumnRecord
    {   
        public:
            ModelColumns()
            {   
                add(m_col_name);
            }
            
            Gtk::TreeModelColumn<Glib::ustring> m_col_name;
    };
        
        ModelColumns m_Columns;
        Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
    
    public:
        MyComboBox(const vector<const char*>& vec, unsigned int startVal)
        {   
            m_refTreeModel = Gtk::ListStore::create(m_Columns);
            set_model(m_refTreeModel);

            
            for ( auto s: vec)
            {   
                Gtk::TreeModel::Row row = *(m_refTreeModel->append());
                row[m_Columns.m_col_name] = s;
            }
            
            pack_start(m_Columns.m_col_name);
            set_active( startVal );
        }
};

void CreateDialog()
{
    std::cout << "Do" << std::endl;
    enum KNOPF
    {
        OK,
        CANCEL
    };

    Gtk::Dialog dialog("Konfiguriere", *winptr, false );

    Gtk::Box* box = dialog.get_vbox();
    MyComboBox cb({{"Eins","Zwei","Drei"}},0);

    box->add( cb );
    dialog.add_button( Gtk::Stock::OK, OK);
    dialog.add_button( Gtk::Stock::CANCEL, CANCEL);
    dialog.set_default_response( CANCEL );

    dialog.show_all_children();

    int ret = dialog.run();
}

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);

    Gtk::Window win;
    winptr=&win;

    Gtk::Button button("Do");
    button.signal_clicked().connect(sigc::ptr_fun(&CreateDialog));
    win.add(button);
    win.show_all_children();
    Gtk::Main::run(win);
}

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]