qt - 在 QMessageBox 中显示 QListView
问题描述
我对 QT 完全陌生,发现它很混乱。
我创建了一个 QListView(称为“listview”)并希望在我的 QMessageBox 中显示它:
const int resultInfo = QMessageBox::information(this, tr("Generate Software"),
tr("The following files will be changed by the program:"),
=> Here the QListView should show up!
QMessageBox::Yes | QMessageBox::No);
if (resultInfo != QMessageBox::Yes) {
return;
}
这有可能吗?
解决方案
QMessageBox
旨在仅提供文本和按钮。见链接。
如果您只想拥有“更多详细信息”文本,请尝试使用detail text property。在这种情况下,您将不得不使用它的构造函数创建消息框并明确设置图标、文本,而不是使用方便的information()
函数。
如果你还想在消息框中有一个列表视图,你应该考虑使用QDialog
,它是QMessageBox
. 下面的小例子:
#include "mainwindow.h"
#include <QDialog>
#include <QListView>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QDialog *dialog = new QDialog{this};
dialog->setWindowTitle(tr("Fancy title"));
auto button = new QPushButton{tr("OK"), this};
connect(button, &QPushButton::clicked, dialog, &QDialog::accept);
QVBoxLayout *layout = new QVBoxLayout{dialog};
layout->addWidget(new QLabel{tr("Description"), this});
layout->addWidget(new QListView{this});
layout->addWidget(button);
dialog->show();
}
MainWindow::~MainWindow()
{
}
推荐阅读
- qt - QML TypeError:对象yy的属性'xx'不是函数
- go - go grpc-go 健康检查如何实现?
- html - 边框半径无法应用于我的 HTML 表格
- jquery - 使用日期选择器聚焦文本框后清除值
- r - 如何用 R 中另一个匹配的列名和行名的值填充数据框?
- java - 如何为新的警报对话框设置参数?
- google-analytics - 无法过滤用户资源管理器谷歌分析
- javascript - 2017-03-26 上的 Javascript 奇怪的日期行为。不能增加一天。为什么?
- python - 使 for 循环附加在所有数据集上
- python - 实时编译面部表情识别结果