![]() |
#571 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,842
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); } } 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. |
![]() |
![]() |
![]() |
#572 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45
Karma: 588278
Join Date: Apr 2016
Device: none
|
Hi Kevin, thanks for the adivce! The QTableView has many desirable features, but what I meant about word wrapping was that the text should flow across multiple lines when there is not enough space, while in the DeleteFiles dialog the overflowing text is replaced by an ellipsis.
Admittedly, for the plugin I'm working on, your solution would nonetheless work well, but in another plugin I have a similar pattern, and there I would like to keep all the labels's text always visible. |
![]() |
![]() |
![]() |
#573 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,842
Karma: 6120478
Join Date: Nov 2009
Device: many
|
Funny, line wrapping is what happens on MacOS on my machine, when shrinking the dialog. I think you can control that.
setTextElideMode(Qt::TextElideMode mode); With Qt::ElideNone. Then enable WordWrap. setWordWrap(true). It is funny you get ellipses and I get wrapping. Update I can remove the ellipses but if I shrink the Dialog too much even with WordWrap on, it will cut off. I never noticed that before. Last edited by KevinH; 08-08-2025 at 04:57 PM. |
![]() |
![]() |
![]() |
#574 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,842
Karma: 6120478
Join Date: Nov 2009
Device: many
|
I think the only way to do this in a QTableView is to use a rich text delegate and set wrap mode to break on words first and when that fails break anyplace.
Last edited by KevinH; Yesterday at 07:21 PM. |
![]() |
![]() |
![]() |
#575 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,842
Karma: 6120478
Join Date: Nov 2009
Device: many
|
I finally figured out how to use a Styled Item Delegate which employed QTextDocument and QTextOptions with Qt::WrapAtWordBoundaryOrAnywhere set to prevent elided or lost text in the DeleteFiles dialog. It took most of today to work out the little nits. The end result is not worth the effort in my opinion.
So if your way works, then it is probably better than the QTableView and ItemDelegate approach. Last edited by KevinH; Yesterday at 07:34 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Loading Plugin in development | Sladd | Development | 6 | 06-17-2014 06:57 PM |
Question for plugin development gurus | DiapDealer | Plugins | 2 | 02-04-2012 11:33 PM |
DR800 Plugin development for DR800/DR1000 | yuri_b | iRex Developer's Corner | 0 | 09-18-2010 09:46 AM |
Device plugin development | reader42 | Plugins | 10 | 03-29-2010 12:39 PM |
Calibre plugin development - Newbie problems | minstrel | Plugins | 5 | 04-12-2009 12:44 PM |