QtNovelUI/TestWidget/widget.cpp

40 lines
1.0 KiB
C++
Raw Normal View History

2022-11-18 23:47:32 +00:00
#include "widget.h"
2022-11-29 03:47:12 +00:00
#include "tools.h"
#include <QPushButton>
#include <QTreeView>
#include <QVBoxLayout>
2022-11-18 23:47:32 +00:00
Widget::Widget(QWidget *parent)
2022-11-29 03:47:12 +00:00
: QWidget(parent), model(new QStandardItemModel(this))
2022-11-18 23:47:32 +00:00
{
2022-11-29 03:47:12 +00:00
auto layout = new QVBoxLayout(this);
auto widget = new QTreeView(this);
layout->addWidget(widget);
widget->setModel(model);
Tools::ModelSyncs<QString>* xmodel = new Tools::ModelSyncs<QString>(model,
[](const QString &d, QStandardItem *n){return d == n->text();},
[](const QString &d, QStandardItem *i){i->setText(d);});
model->appendRow(new QStandardItem("sldkjflkdf"));
auto button = new QPushButton("click");
layout->addWidget(button);
connect(button, &QPushButton::clicked, [this, xmodel](){
xmodel->presentSync([](const QString &x){
if(x.length() > 3)
return QList<QString>();
return QList<QString>() << x + "a" << x + "b" << x + "c" << x + "d";
});
});
2022-11-18 23:47:32 +00:00
}
Widget::~Widget()
{
}