如何设置gtkmm窗口在屏幕中央打开?

时间:2013-02-14 23:05:00

标签: c++ gtkmm

我正在尝试让我的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();
}

和我的Header文件:

#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

1 个答案:

答案 0 :(得分:3)

您的viewMenu类继承自Gtk :: Window类。只需使用set_position函数设置窗口的位置即可。而不是:

window.set_position(Gtk::WIN_POS_CENTER);

使用:

set_position(Gtk::WIN_POS_CENTER);