一、Qt模态界面设置setWindowModality禁止其他界面响应
Qt中的QWidget对象自带setWindowModality(type)方法,用以设置窗口模态类型。
参数type可选为一下三种:
Qt::NonModal 非模态:正常模式
Qt::WindowModal 半模态:窗口级模态对话框,阻塞父窗口、父窗口的父窗口及兄弟窗口。
Qt::ApplicationModal 模态:应用程序级模态对话框,阻塞整个应用程序的所有窗口。
三、代码示例
void MainWindow::on_toolButton_NewWidget_clicked()
{
Widget_ui *new_ui = new Widget_ui(this);//创建新界面窗口
new_ui->setWindowModality(Qt::ApplicationModal);//设置模态
connect(new_ui,&new_ui->Tx_NewSig,this,&MainWindow::Rx_NewSig);//绑定当前界面的信号槽
new_ui->show();//显示当前新创建的界面窗口
}
四、
当使用QPalette为窗口设定背景并使用QPalette::Window时
必须调用setAutoFillBackground(true)!!!
lable1.setAutoFillBackground(True)给label设置背景的时候,这个属性是需要和调色板结合起来一起使用才行
https://blog.csdn.net/jeekmary/article/details/79156597
#初始化标签控件
lable1.setText("文本标签")
lable1.setAutoFillBackground(True)
palette = QPalette()
palette.setColor(QPalette.Window, Qt.red)
lable1.setPalette(palette)
lable1.setAlignment(Qt.AlignCenter)
解释下上面的代码,setAutoFillBackground(True)表示的是自动填充背景,如果想使用后面的代码。这里必须要设置为True
palette = QPalette(),这里是实例化一个调色板对象,给label设置背景那么肯定需要一个颜色器来生成,这里的QPalette就是这个颜色器
palette.setColor(QPalette.Window, Qt.red)这里就是颜色器设置颜色
lable1.setPalette(palette)这里就是想颜色器上的颜色整合到label上去