Qt图形界面开发---信号与槽

文章目录

  • Qt图形界面开发---信号与槽
      • 1. 窗口几何尺寸
      • 2. 模态与非模态对话框
      • 3. 信号与槽

Qt图形界面开发—信号与槽

1. 窗口几何尺寸

// Including the window frame: x(), y(), frameGeometry(), pos(), and move().    含边框 
// Excluding the window frame: geometry(), width(), height(), rect(), and size(). 不含边框

//含边框
qDebug()<<"openGLWidget‐>frameGeometry();"<openGLWidget‐>frameGeometry();
//不含边框
qDebug()<<"openGLWidget‐>geometry();"<openGLWidget‐>geometry();

2. 模态与非模态对话框

#include "widget.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    QDialog *dlg=new QDialog(&w);
    dlg‐>exec();	//模态对话框
    /*dlg->show();	非模态对话框*/
    return a.exec();
}

3. 信号与槽

在Qt中使用信号和槽机制来完成对象之间的协同操作。 相当于Win32的回调函数

/* 1. 自动关联 */
/* 在ui界面,右键点击控件对象,转到槽,选择需要响应的事件 */
/* 2. 使用 connect关联 */
/* 格式:connect(发射者对象指针, SIGNAL(信号函数) , 接收者对象指针, SLOT(槽函数),连接方式) */
connect(ui->pushbutton,SIGNAL(clicked()),this,SLOT(pushbuttonSlot));
/* 3. 设计模式中关联 (不推荐) */
/* 在 ui界面的设计模式中,通过连线进行信号与槽的关联 */

你可能感兴趣的:(QT)