gtkmm 中的程序不会显示按钮
Program in gtkmm will not show buttons
我正在尝试用gtkmm编写程序,但按钮不会显示。 我已经做了我所知道的一切来显示这些按钮,但没有任何效果。 我什至在主文件和win_home.cpp文件中都包含了"全部显示"方法,但仍然没有任何反应。 然而,程序确实会通过代码,因为cout语句都被打印出来了。 有谁知道为什么这些按钮不会出现?
主.cpp:
#include <gtkmm.h>
#include <iostream>
#include "win_home.h"
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "com.InIT.InITPortal");
std::cout << "Creating Portal Window" << std::endl;
HomeGUI win_home;
win_home.set_default_size(600,400);
win_home.set_title("St. George InIT Home");
return app->run(win_home);
}
win_home.cpp:
#include "win_home.h"
HomeGUI::HomeGUI()
{
//build interface/gui
this->buildInterface();
//show_all_children();
//register Handlers
//this->registerHandlers();
}
HomeGUI::~HomeGUI()
{
}
void HomeGUI::buildInterface()
{
std::cout << "Building Portal Interface" << std::endl;
m_portal_rowbox = Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 5);
add(m_portal_rowbox);
Gtk::Button m_pia_button = Gtk::Button("Printer Install Assistant");
m_portal_rowbox.pack_start(m_pia_button, false, false, 0);
m_pia_button.show();
Gtk::Button m_inventory_button = Gtk::Button("Inventory");
m_inventory_button.show();
m_portal_rowbox.pack_start(m_inventory_button, false, false, 0);
m_inventory_button.show();
//add(m_portal_rowbox);
//m_portal_rowbox.show_all();
m_portal_rowbox.show();
this->show_all_children();
std::cout << "Completed Portal Interface" << std::endl;
return;
}
void HomeGUI::registerHandlers()
{
}
在无效HomeGUI::buildInterface()
中,您已经构建了 2 个按钮,并将其添加到您的盒子容器中。当函数返回时,按钮将被销毁,因为它们现在超出了范围。由于它们不再存在,因此它们不可见。
因此,对于您的第一个按钮,您将使用如下所示的内容:
Gtk::Button * m_pia_button = Gtk::manage(
new Gtk::Button("Printer Install Assistant"));
m_portal_rowbox.pack_start(&m_pia_button, false, false, 0);
m_pia_button.show();
我希望您需要在窗口的整个生命周期内轻松访问按钮。最简单的方法是将按钮作为类的成员。它将被构造为一个空按钮,之后您只需要设置标签。
class HomeGUI {
....
// A button (empty)
Gtk::Button m_pia_button;
....
};
....
void HomeGUI::buildInterface()
{
....
m_pia_button.set_label("Printer Install Assistant");
m_portal_rowbox.pack_start(m_pia_button, false, false, 0);
m_pia_button.show();
....
}
相关文章:
- Qt自定义QPush按钮未显示在布局上
- 如何以编程方式显示功能区按钮的下拉菜单?
- 以编程方式在任何按钮上突出显示 Qt 鼠标悬停按钮
- QTool按钮按Alt后显示菜单
- 在主窗口之前显示登录对话框并隐藏主窗口按钮
- 隐藏、显示、添加或删除功能区中的按钮?
- 单击"推送"按钮应使用Qt C++在不同的窗口中显示绘图
- 如何隐藏最大化和最小化按钮并在qml应用程序窗口中显示关闭按钮?
- 如何使用任务栏按钮显示进度条?
- 如何通过单击按钮在QTextEdit中显示文本?
- 如何在QPush按钮悬停时设置突出显示
- GTK 卷按钮图标显示初始值 c++
- gtkmm 中的程序不会显示按钮
- 与按钮关联的 QLabel 未显示
- Qt:QVideoWidget 不显示并禁用应用程序中的所有按钮,或者极大地减慢应用程序的速度
- 嗨,我正在尝试编码一个允许用户在Visual C 中登录的按钮,程序正在运行,但表单对话框未显示
- 如何使 UI 对象仅在单击按钮后显示在对话框中
- C++(按下按钮1,显示位图"P",2秒,隐藏位图"P")
- QML 矩形按钮突出显示延迟
- 要将QPushButton放置到图形视图上..但是没有显示按钮