Преобразование списка элементов в qt listwidget в переключатели

Я создал приложение, в котором файлы из каталога отображаются в qlistwidget.

Теперь проблема в том, что я хочу, чтобы этот список отображался в виде списка переключателей, чтобы пользователь мог выбрать переключатель и сохранить адрес выбранного файла. Также должна отображаться ошибка, если пользователь не выбирает переключатель и нажимает кнопку «Далее».

Я использую Visual Studio для кодирования графического интерфейса вместо QT Creator.

Мой код до сих пор:

.файл hpp

#pragma once
#include <QWidget>

#include "ui_secondform.h"
#include "thirdform.hpp"#include <QRegExp>
#include <QDir>
#include <QDebug>

class SecondForm : public QWidget {
Q_OBJECT

public:
SecondForm(QWidget * parent = Q_NULLPTR);
~SecondForm();
QString processText();
signals:
void firstform();
public slots:
void on_pushButton_next2_clicked();
void on_pushButton_back2_clicked();
void on_lineEdit_textChanged(const QString &arg1);
//void onNewTextEntered(const QString &text);
//void on_lineEdit_textChanged(const QString &arg1);
private:
Ui::SecondForm ui;
ThirdForm *third;
QStringList fileList;
};

.файл cpp:

#include "secondform.hpp"#include "firstform.h"
SecondForm::SecondForm(QWidget * parent) : QWidget(parent) {
ui.setupUi(this);
third = new ThirdForm();
// connected to the slot start the main window on the button in the second window
connect(third, &ThirdForm::secondform, this, &SecondForm::show);
//QString dir = processText();
QDir testPath("D://");
testPath.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
fileList = testPath.entryList();
ui.listWidget->addItems(fileList);
}

SecondForm::~SecondForm() {

}
void SecondForm::on_pushButton_back2_clicked() {
this->hide();
emit firstform();
}
void SecondForm::on_pushButton_next2_clicked() {
this->close();
third->show();
}
void SecondForm::on_lineEdit_textChanged(const QString &arg1) {
QRegExp regExp(arg1, Qt::CaseInsensitive, QRegExp::Wildcard);
ui.listWidget->clear();
ui.listWidget->addItems(fileList.filter(regExp));
}
QString SecondForm::processText()
{
FirstForm first;
const QString dir = first.lineEdit()->text();
return dir;
// do something with the text
}

Выход:

изображение для вывода

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]