TextView Gtkmm - 改变大小
Posted
技术标签:
【中文标题】TextView Gtkmm - 改变大小【英文标题】:TextView Gtkmm - Changing Size 【发布时间】:2017-08-21 17:00:43 【问题描述】:我正在尝试在 Gtkmm 中构建一个窗口。我所有的小部件都出现了,但我无法调整我的文本视图的高度。我试过 set_border_window_size() 和 set_size_request(),但都没有工作。也就是说,它们不会改变 textview 大小的任何方面。
这是我的窗口构造函数:
UDPWindow::UDPWindow() :
Gtk::ApplicationWindow(),
box_hBox(Gtk::ORIENTATION_HORIZONTAL, 7),
box_vBox1(Gtk::ORIENTATION_VERTICAL, 7),
box_vBox2(Gtk::ORIENTATION_VERTICAL, 7),
box_sentData(Gtk::ORIENTATION_VERTICAL, 7),
box_receivedData(Gtk::ORIENTATION_VERTICAL, 7),
frm_sentData("Sent Data"),
frm_receivedData("Received Data"),
lbl_sendMessage("Message to Send"),
lbl_sendDevice("Select Device"),
btn_send("Send Message"),
btn_quit("Quit"),
comms(NULL)
// set up UDP Communications
//comms = new UDP_Communicator();
uchar device[3] = 1, 2, 3;
/*device[0] = comms->createNewSocket(52088, "192.168.1.2", 2);
device[1] = comms->createNewSocket(8090, "192.168.1.3", 2);
device[2] = comms->createNewSocket(48183, "192.168.1.4", 2);
comms->start();
comms->postMessage(MSG_ADD_DEVICE_TO_HANDSHAKE, "", device[0]);
comms->postMessage(MSG_ADD_DEVICE_TO_HANDSHAKE, "", device[1]);
comms->postMessage(MSG_START_HANDSHAKE, "", 0);*/
//fill combo box
std::stringstream str;
str << (int)device[0];
cmb_sendDevice.append(str.str());
str.str(std::string());
str.clear();
str << (int)device[1];
cmb_sendDevice.append(str.str());
str.str(std::string());
str.clear();
str << (int)device[2];
cmb_sendDevice.append(str.str());
cmb_sendDevice.set_active(0);
// set up message text box
txt_sendMessage.set_max_length(50);
txt_sendMessage.set_text("Enter Message");
// set up quit button
btn_quit.signal_clicked().connect(sigc::mem_fun(*this, &UDPWindow::on_btn_quit));
// set up send button
btn_send.signal_clicked().connect(sigc::mem_fun(*this, &UDPWindow::on_btn_send));
// set up sent data scroll text
txt_sentData.set_editable(false);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_TOP, 15);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_BOTTOM, 15);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_LEFT, 100);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_RIGHT, 100);
txt_sentData.set_size_request(-1, 100);
scrl_sentData.add(txt_sentData);
scrl_sentData.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
// set up received data scroll text
txt_receivedData.set_editable(false);
scrl_receivedData.add(txt_receivedData);
scrl_receivedData.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
add(box_hBox);
box_hBox.pack_start(box_vBox1, Gtk::PACK_SHRINK);
box_sentData.pack_start(lbl_sendDevice, Gtk::PACK_SHRINK);
box_sentData.pack_start(cmb_sendDevice, Gtk::PACK_SHRINK);
box_sentData.pack_start(lbl_sendMessage, Gtk::PACK_SHRINK);
box_sentData.pack_start(txt_sendMessage, Gtk::PACK_SHRINK);
box_sentData.pack_start(btn_send, Gtk::PACK_SHRINK);
box_sentData.pack_start(scrl_sentData, Gtk::PACK_SHRINK);
frm_sentData.add(box_sentData);
box_vBox1.pack_start(frm_sentData, Gtk::PACK_SHRINK);
box_hBox.pack_start(box_vBox2, Gtk::PACK_SHRINK);
box_receivedData.pack_start(scrl_receivedData, Gtk::PACK_SHRINK);
box_receivedData.pack_start(btn_quit, Gtk::PACK_SHRINK);
frm_receivedData.add(box_receivedData);
box_vBox2.pack_start(frm_receivedData, Gtk::PACK_SHRINK);
this->show_all();
Gtk::window 附加了一个set_default_size()
函数,但作为一个小部件,textview 似乎无法访问它。我不知道该怎么办。
上面发布的代码同时包含了 set_border_window_size() 和 set_size_request(),尽管一次只使用了一组函数。
【问题讨论】:
【参考方案1】:因为 TextView 在 ScrolledWindow 内部,所以 ScrolledWindow 的属性决定了大小。
scrl_sentData.set_size_request(-1, 100);
【讨论】:
以上是关于TextView Gtkmm - 改变大小的主要内容,如果未能解决你的问题,请参考以下文章
如何把android textView字体大小固定写死,而不随系统设置字体大小的改变而改变。
TextView系列:给定宽度,根据内容长度,自动改变字体大小