Reputation: 1933
I'm trying to create a fullscreen window covered with an image and one entry widget in the middle of the window.
I already have the fullscreen window with the image, however, I'm struggling with positioning the entry box exactly in the middle of the window. I tried Gtk::Alignment
, Gtk::VBox
, Gtk::HBox
, Gtk::Table
and many other containers, but to be honest, I don't really understand all the containers how do they behave. I am used to WIN32 API with absolute positioning and this is way different. I know I can use something like fixed positioning in Gtk/gtkmm, however, it does not seem like the cleanest solution to me.
class App : public Gtk::Window {
public:
[...]
App() {
fullscreen();
Gdk::Rectangle rec = get_screen()->get_monitor_workarea(get_screen()->get_primary_monitor());
set_default_size(rec.get_width(), rec.get_height());
show();
m_bgImage.set("image.jpg");
m_layout.add(m_bgImage);
m_entry.set_size_request(300, 30);
m_entry.set_opacity(0.5);
m_entry.set_visibility(false);
m_entry.signal_activate().connect(sigc::mem_fun(*this, &PadlockGui::onPasswordEntryReturn));
m_entry.set_icon_from_icon_name("edit-clear", Gtk::ENTRY_ICON_SECONDARY);
m_entry.signal_icon_press().connect(sigc::mem_fun(*this, &PadlockGui::clearPasswordEntry));
m_layout.add(m_entry);
add(m_layout);
show_all_children();
}
private:
Gtk::Layout m_layout;
Gtk::Image m_bgImage;
Gtk::Entry m_entry;
[...]
};
Here is a picture of my current situation:
Here is what I am trying to achieve:
Upvotes: 0
Views: 670
Reputation: 57854
I would suggest using CSS to create the background image rather than Gtk::Image
. Then you can just put the entry directly in the window, and make sure its expand
property is set to false and its halign
and valign
properties are centered.
Upvotes: 1