我正在尝试在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(),即使一次只使用了一组函数。
答案 0 :(得分:0)
因为TextView位于ScrolledWindow中,所以ScrolledWindow的属性决定了它的大小。
scrl_sentData.set_size_request(-1, 100);