当最后一个窗体被关闭,应用程序就结束了。QApplication' 的quitOnLastWindowClosed 属性设为 false,程序会一直运行,直到我们调用QApplication::quit()
一个对话框如果调用 show() 就是非模态的(如果之前调用了setModal() 则是模态的 );如果调用exec() 则是模态的。
QDialog::exec() 返回true (if the dialog is accepted) 或false (otherwise),通常OK 按钮连接 accept() ,Cancel 连接 reject()
QTableWidget::setCurrentCell() 接受两个参数,一个是行index, 一个是列index
QString::mid() 返回从start position 到尾部的字符串。
void MainWindow::goToCell()
{
GoToCellDialog *dialog = new GoToCellDialog(this);
if (dialog->exec()) {
QString str = dialog->lineEdit->text().toUpper();
spreadsheet->setCurrentCell(str.mid(1).toInt() - 1,
str[0].unicode() - 'A');
}
delete dialog;
}
模态对话框一般用完就销毁
本文介绍了Qt中对话框的使用方法,包括模态与非模态对话框的区别及实现方式,并展示了如何通过QTableWidget定位单元格。此外,还讨论了如何设置QApplication在最后一个窗口关闭后的行为。
1250

被折叠的 条评论
为什么被折叠?



