弹出式窗体他的要求如下:
1.点击按钮弹出这个窗体在按钮旁边,并可编辑内容。
2.鼠标点击其他地方(非弹出窗体),这个窗体关闭
注意:1.这里基类必须是QDialog.
2.创建他时必须指定parent.
3.这个窗体必须new出来。
//头文件
class GTZLSetWidget : public QDialog
{
Q_OBJECT
public:
explicit GTZLSetWidget(QWidget *parent = 0);
~GTZLSetWidget();
public slots:
private slots:
void onTimer();
private:
void setupUI();
private:
QTimer * m_timer;
};
//实现文件
GTZLSetWidget::GTZLSetWidget(QWidget *parent)
:QDialog(parent)
{
setupUI();
m_timer->start(100);
}
GTZLSetWidget::~GTZLSetWidget()
{
m_timer->stop();
if(m_timer)delete m_timer;
}
void GTZLSetWidget::setupUI()
{
this->setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
//this->setWindowFlags(Qt::FramelessWindowHint | Qt::Window);
//this->setAttribute(Qt::WA_TranslucentBackground);
}
void GTZLSetWidget::onTimer()
{
if(!this->isActiveWindow())
{
this->close();
this->deleteLater();
}
}
//调用点函数,记住,这里有点特殊,这个窗体必须new出来否则窗体无法获取到键盘输入焦点,必须指定parent否者无法正常显示
void GZLTestAccountView::onSetting()
{
QPoint pt = m_settingButton->pos();
pt = this->mapToGlobal(pt);
int h = m_settingButton->height();
GTZLSetWidget *setting = new GTZLSetWidget(this);
pt.setY(pt.y()+h);
setting->move(pt);
setting->show();
setting->raise();
setting->setFocus();
}