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
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list