Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] cannot create two QT window

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] cannot create two QT window


Chronological Thread 
  • From: Sébastien Meunier <>
  • To:
  • Subject: Re: [cgal-discuss] cannot create two QT window
  • Date: Sat, 19 Apr 2008 14:10:37 +0200

Hi,

I've never used the CGAL Qt_widget since I don't work anymore with Qt3 but with Qt4, but more generally when you use a Qt widget with specific needs you should define your own widget class, deriving from QtWidget (or here CGAL::Qt_widget) and then you can redefine your own keyPressEvent and mousePressEvent methods.

If your application is made with 2 widgets, I would say that your "myProgram" class should be the main one and thus you only have to create a new class for your second widget (if the behaviour is different).

Hope it'll help

Sebastien
HMI Designer

Mahmood Naderan a écrit :
Hi,
How can I create two independent QT window? Here is what I wrote:
in the main():
QApplication app (argc, argv);
myProgram *w = new myProgram (....);
app.setMainWidget (w);
w->show();
return (app.exec());
In the constructor of myProgram class, I wrote:
// Create first window. widget = new CGAL::Qt_widget(this);
widget->resize (INIT_WIDTH, INIT_HEIGHT);
widget->set_window (x_min, x_max, y_min, y_max);
connect(widget, SIGNAL(redraw_on_back()), this, SLOT(redraw_win()));
connect(widget, SIGNAL(s_mousePressEvent(QMouseEvent*)), this,
SLOT(mousePressEvent (QMouseEvent*)));
setCentralWidget(widget);
redraw_win();
// create second window
mWid = new CGAL::Qt_widget(this);
mWid->resize (INIT_WIDTH, INIT_HEIGHT);
mWid->set_window (x_min, x_max, y_min, y_max);
connect(mWid, SIGNAL(redraw_on_back()), this,
SLOT(redraw_winMahmood()));
connect(mWid, SIGNAL(s_keyPressEvent(QKeyEvent*)), this,
SLOT(keyPressEvent(QKeyEvent*)));
redraw_winMahmood();
functions for second window are:
void keyPressEvent(QKeyEvent *e)
{
mWid->redraw();
}
void redraw_winMahmood()
{ // based on CGAL manual
typedef CGAL::Cartesian<int> Rep;
typedef CGAL::Point_2<Rep> Point_2;
typedef CGAL::Segment_2<Rep> Segment;
mWid->resize(600, 600);
mWid->set_window(0, 600, 0, 600);
mWid->show();
mWid->lock();
*mWid << CGAL::BackgroundColor(CGAL::ORANGE) << CGAL::RED;
*mWid << Segment(Point_2(100,100), Point_2(400,400));
mWid->unlock();
}
The first window functions are ok; I mean if I only have the first window, it works. The problem is when I add second window, after I press a key (because there should be a key event in order to create second window), strangly the first window closes!!!
What is wrong with it?

-------------------
Mahmood Naderan
http://ce.sharif.edu/~m_naderan




____________________________________________________________________________________
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ




  • cannot create two QT window, Mahmood Naderan, 04/19/2008
    • Re: [cgal-discuss] cannot create two QT window, Sébastien Meunier, 04/19/2008

Archive powered by MHonArc 2.6.16.

Top of Page