1

I'm rather new to C++, I have a bit of experience with MCV programming in Java. im using GTKmm on C++ What I'm trying to do is writing an application for teaching assistants to submit and edit applications to various positions, and administrators to come in view, and accept these applications.

What I'm trying to do at the begging is create 3 'frames' (I'm working on the submitting application for students only at the moment)

  • This first will have 2 buttons 1 for selecting if you're a student/admin

  • Upon clicking you're a student I want to hide this frame and show my second frame

  • The second frame will have another 2 buttons one for creating an application, and the other for editing applications

My core problem is that I don't understand how to switch between the frames, I've written all the code for my Model, and understand everything I want it to do however I cant seem to find how to do this...

My only idea would be to create windows for each of these, make them look all nice w/e, then when a button is pressed have that window close and a string written to file I can access to see which button has been pressed, then open a new window accordingly. Should I do it like this or is there a better way?

4

3 に答える 3

3

I think I can suggest a better/more idiomatic option for any version >= GTK+ 3.10 - which, to be fair, arrived about half a year after the accepted answer.

If you want to switch between widgets one-at-a-time without any accessories like tabs, then a Gtk::Stack seems like a better option. Because it's specifically geared for one-at-a-time presentation, without any redundancy and (theoretical) overhead from a Notebook's manual tabbing features, which you'd just be disabling straight away! It's a container with multiple children, with one visible at any given moment, and of course methods to change the active child.

You can hook up your own widgets and/or events to manage which of the Stack's children is shown. Alternatively - albeit possibly just restoring the redundancy in this case - there's a StackSwitcher companion widget, which is pretty much a vertical tab-bar as seen in the GTK+ demo and GNOME Tweak Tool.

于 2016-04-17T09:43:00.927 に答える
1

最も簡単な方法は、ノートブックウィジェットを使用することです。メソッドを使用して、表示するページを制御するため、タブを非表示にできますset_show_tabs(false)。メソッドを使用して各フレームのトップレベルウィジェットをペインに配置し、を使用してフレームをappend_page()切り替えますset_current_page()。メソッドを使用して、気が散る場合はノートブックの斜角を非表示にすることをお勧めしますset_show_bevel(false)

シグナルを使用して、1つのページのウィジェット(たとえば、「私は学生です」ボタン)に何かを実行させます(たとえば、2番目のページに移動します)。これが何を意味するのか、それをどのように行うのかわからない場合は、gtkmmチュートリアルを読んでください。これについて、さらに詳しく説明されています。

于 2013-02-10T04:31:41.443 に答える
0

A bit too late ! But here is my try :

Gtk::Notebook is great but it is not ideal in switching between app frames on menu item clicks. Gtk::Stack, since gtkmm 3.10, exists to mitigate this. Assuming you're using glade and Gtk::Builder :

class

class AppName : public Gtk::ApplicationWindow
{
public:
//...Your app methods and callbacks
void on_mb_itemname_selected(); // The call back for our menu item click/select
private:
//Builder which will help build the app from a .glade file
Glib::RefPtr<Gtk::Builder> _builder;
//...
//Your menu item to activate a particular frame
Gtk::MenuItem * _mb_itemname;
//Your handle to Gtk::Stack which is usually the stack for the whole app
 Gtk::Stack * _app_stack;
//...
}

constructor

AppName::AppName(BaseObjectType *cobj,
                 Glib::RefPtr<Gtk::Builder>& ref_builder)
                :Gtk::ApplicationWindow(cobj),_builder(ref_builder)
{
//.. Other setup
_builder->get_widget("your_glade_id_to_stack",_app_stack);
_builder->get_widget("your_glade_id_to_menu_item",_mb_itemname);

// Connect signal_select of our menu item to appropriate signal handler.
mb_itemname->signal_select().connect(
          sigc::mem_fun(*this,&AppName::on_mb_itemname_selected));
}

our callback

void AppName::on_mb_itemname_selected()
{
// Change the visible child of the stack concerned.
Gtk::StackTransitionType ttype = STACK_TRANSITION_TYPE_NONE;
_app_stack->set_visible_child("your_widget_name",ttype);
// Note that widget name is not widget glade id.
// You can set  your widget under name Packing -> Name
return; 
}
于 2019-05-01T07:05:32.553 に答える