Qt 多窗体、复用窗口的使用

avatar
作者
猴君
阅读量:2

1.继承自QWidge的窗口的呈现,作为tabPage呈现,作为独立窗口呈现

2.继承自QMainWindow的窗口的呈现,作为abPage呈现,作为独立窗口呈现

1. 继承自QWidge的窗口的呈现

1.1 作为tabPage呈现

void MutiWindowExample::on_actWidgetInsite_triggered() {     TFormDoc *form = new TFormDoc(this);     //关闭时 自动删除  释放     form->setAttribute(Qt::WA_DeleteOnClose);     int cur= ui->tabWidget->addTab(form,QString::asprintf("Doc %d",ui->tabWidget->count()));     ui->tabWidget->setVisible(true);     connect(form,&TFormDoc::titleChanged,this,&MutiWindowExample::do_changeTabTitle); } 

1.2 作为独立窗口呈现

void MutiWindowExample::on_actWidget_triggered() {     TFormDoc *form = new TFormDoc(this);     //关闭时 自动删除  释放     form->setAttribute(Qt::WA_DeleteOnClose);     form->setWindowTitle("基于Widget的窗口,无父窗口,关闭时删除释放");     //设置成window 窗口标识     form->setWindowFlag(Qt::Window,true);     form->setWindowOpacity(0.9);     //独立窗口显示     form->show(); }

2. 继承自QMainWindow的窗口的呈现

2.1 作为tabPage呈现

 void MutiWindowExample::on_actWindowInsite_triggered() {     CustomDialogExample *form = new CustomDialogExample(this);     form->setAttribute(Qt::WA_DeleteOnClose);//关闭立即释放     int cur = ui->tabWidget->addTab(form,QString::asprintf("Table %d",ui->tabWidget->count()));     ui->tabWidget->setCurrentIndex(cur);     ui->tabWidget->setVisible(true); }

2.2 作为独立窗口呈现

void MutiWindowExample::on_actWindow_triggered() {     CustomDialogExample *form = new CustomDialogExample(this);     form->setAttribute(Qt::WA_DeleteOnClose);//关闭立即释放     form->setWindowTitle("基于QMainWindow的窗口");     form->statusBar();     form->show(); } 

效果

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!