View Single Post
Old 08-08-2025, 02:27 PM   #571
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,859
Karma: 6120478
Join Date: Nov 2009
Device: many
If you want to do that to an entire list of checkboxes you may want to check out Sigil/src/Dialogs/DeleteFiles.cpp and [.h] and Sigil/src/Form_Files/DeleteFiles.ui


To see it in action, run Sigil and open a junk epub with lots of files. In BookBrowser highlight a bunch of files and right click and select Delete.

Sigil will show a QDialog with a list of checkboxes and file path right beside it. Then grab the dialog and resize it to make it really small and you will see that the filepaths are nicely wrapped.

Is that what you want?

This is accomplished by using a QTableView with two columns, the first for the checkmark and the second for the file path.

Code:
void DeleteFiles::SetUpTable()
{
    QStringList header;
    QPushButton *delete_button = ui.buttonBox->button(QDialogButtonBox::Ok);
    delete_button->setText(tr("Delete Marked Files"));
    header.append(tr("Delete"));
    header.append(tr("File"));
    m_Model.setHorizontalHeaderLabels(header);
    ui.Table->setModel(&m_Model);
    // Make the header fill all the available space
    ui.Table->horizontalHeader()->setStretchLastSection(true);
    ui.Table->verticalHeader()->setVisible(false);
    ui.Table->setSortingEnabled(true);
    ui.Table->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui.Table->setSelectionMode(QAbstractItemView::SingleSelection);
    ui.Table->setAlternatingRowColors(true);
}
Code:
DeleteFiles::DeleteFiles(QStringList files_to_delete, QWidget *parent)
    :
    QDialog(parent),
    m_FilesToDelete(files_to_delete)
{
    ui.setupUi(this);
    ConnectSignals();
    SetUpTable();
    ReadSettings();
    foreach(QString filepath, m_FilesToDelete) {
        QList<QStandardItem *> rowItems;
        // Checkbox
        QStandardItem *checkbox_item = new QStandardItem();
        checkbox_item->setCheckable(true);
        checkbox_item->setCheckState(Qt::Checked);
        rowItems << checkbox_item;
        // File Path
        QStandardItem *file_item = new QStandardItem();
        file_item->setText(filepath);
        rowItems << file_item;

        for (int i = 0; i < rowItems.count(); i++) {
            rowItems[i]->setEditable(false);
        }

        m_Model.appendRow(rowItems);
    }
}
One advantage of using a QDialog with a QTableView is that you can easily get alternative row colours and can add a check all or uncheck all element.

If you like the QTableView approach and it does what you want, I would be happy to take a stab at converting it to python if you would like.

Just let me know.

Last edited by KevinH; 08-08-2025 at 03:09 PM.
KevinH is online now   Reply With Quote