1

我正在尝试让我在 GTKmm 中的窗口在屏幕中央打开,但我在网上的任何地方都找不到有效的解决方案。有什么见解吗?

我一直在尝试我能想到的一切,但没有结果......

这是我的代码:

#include "viewMenu.h"
#include <iostream>
#include <fstream>
#define MAX_BUF 10

viewMenu::viewMenu()
: frmMenu("cuTAES Review Menu"), 
  lblChooser("Select Course : "), 
  lblCourses(""),
  lblView(" View "),
 lblAppInfo(" Application Info "), 
  lblStuInfo(" Student Info "), 
  btnView(" View this Application "), 
  btnBack(" Back "),
  frameTable(4,4,true)
{
  set_title("cuTAES Review Menu ");
  //set_border_width(50);
  add(frameTable);

  window.set_position(Gtk::WIN_POS_CENTER);

  //frmMenu.add(lblChooser);
  //frameTable.attach(frmMenu,0,1,0,0);

  frameTable.attach(lblChooser, 1,2,0,1);
  char text[MAX_BUF];
  std::ifstream inFile("courses.txt", std::ios::in);
  if(!inFile){
    exit(1);
  }
  while(!inFile.eof()) {
    inFile.getline(text,MAX_BUF);
    cboCourse.append(text);
  }

  frameTable.attach(cboCourse, 2,3,0,1);

  //set up my table
  frameTable.attach(lblView, 0,1,0,1);
  frameTable.attach(lblStuInfo, 0,1,1,2);
  frameTable.attach(lblAppInfo, 2,3,1,2);
  btnView.signal_clicked().connect(sigc::mem_fun(*this,&viewMenu::btnView_clicked));
  frameTable.attach(btnView,3,4,0,1);

  btnBack.signal_clicked().connect(sigc::mem_fun(*this, &viewMenu::btnBack_clicked));
  frameTable.attach(btnBack,3,4,3,4);

  show_all_children();
}

和我的头文件:

#ifndef VIEWMENU_H
#define VIEWMENU_H

#include <gtkmm.h>

class viewMenu : public Gtk::Window
{

public:
  viewMenu();
  virtual ~viewMenu();

protected:
  //Signal handlers:
  void btnView_clicked();

  void btnBack_clicked();

  //Member widgets:
  Gtk::Table frameTable;
  Gtk::Label lblChooser,lblCourses, lblView, lblAppInfo, lblStuInfo, lblCourseDrop;  
  Gtk::Frame frmMenu;
  Gtk::Button btnView, btnBack;
  Gtk::ComboBoxText cboCourse;
  Gtk::Window window;
};

#endif // MAINMENU_H
4

1 回答 1

3

您的 viewMenu 类继承自 Gtk::Window 类。只需使用 set_position 函数来设置窗口的位置。代替:

window.set_position(Gtk::WIN_POS_CENTER);

利用:

set_position(Gtk::WIN_POS_CENTER);
于 2014-01-12T15:53:37.410 回答