读书人

继承于QWidhet类窗口父子窗口如何建

发布时间: 2012-12-16 12:02:32 作者: rapoo

继承于QWidhet类窗口,父子窗口怎么建立
本帖最后由 jackzhangxy 于 2012-10-24 00:58:35 编辑


.h
#include <QtGui>
class IrregularWidget : public QWidget
{
Q_OBJECT
public:
IrregularWidget(QWidget *parent = 0);
};

class NewWindow: public QWidget
{
Q_OBJECT
public:
NewWindow(QWidget *parent = 0);
};




.cpp
#include ".h"
IrregularWidget::IrregularWidget(QWidget *parent)
: QWidget(parent)
{
PushButton *button = new PushButton(this);
button->move(180,145);
connect(button, SIGNAL(clicked()), this, SLOT(NewWindow()));
}

NewWindow::NewWindow(QWidget *parent)
: QWidget(parent)
{
}


我要实现在这个父窗口外面弹出这个子窗口在桌面上并且置顶。

这个NewWindow应该怎么写?

应该传什么参数进去呢?

还有怎么获取父窗口的句柄呢?



[最优解释]
引用:
C/C++ code

.h
#include <QtGui>
class IrregularWidget : public QWidget
{
Q_OBJECT
public:
IrregularWidget(QWidget *parent = 0);
};

class NewWindow: public QWidget
{
Q_OBJECT
public:
……

使用模态对话框模式,你再坛子里面搜Qt 模态对话框,这个东西你能找到。
如何获取父类指针,你看下assistant,找下parent关键词,你应该很容易找到
[其他解释]
父窗口就是构造函数的那个参数啊;

你是要在IrregularWidget 这个窗口上弹出NewWindow窗口是吧?

那就这样写:

NewWindow * window = new NewWindow(this);

窗口置顶:
setWindowFlags(Qt::WindowStaysOnTopHint);
此函数只有放在 窗口类的成员函数中使用才有效,比如你要让NewWindow置顶,就只能在NewWindow的成员函数中使用这个置顶的函数,
你调用window ->setWindowFlags(Qt::WindowStaysOnTopHint);貌似无效(记得是这样)。



读书人网 >QT开发

热点推荐