Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
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,848
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 offline   Reply With Quote
Old 08-08-2025, 04:15 PM   #572
wrCisco
Enthusiast
wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.
 
Posts: 46
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.
wrCisco is offline   Reply With Quote
Old 08-08-2025, 04:46 PM   #573
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,848
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.
KevinH is offline   Reply With Quote
Old 08-08-2025, 05:06 PM   #574
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,848
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; 08-09-2025 at 07:21 PM.
KevinH is offline   Reply With Quote
Old 08-09-2025, 07:30 PM   #575
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,848
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; 08-09-2025 at 07:34 PM.
KevinH is offline   Reply With Quote
Old Yesterday, 04:21 PM   #576
wrCisco
Enthusiast
wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.wrCisco ought to be getting tired of karma fortunes by now.
 
Posts: 46
Karma: 588278
Join Date: Apr 2016
Device: none
Yes, it seems that word wrapping without complex strategies is not entirely consistent across platforms (I'm testing on Windows 11 - Sigil 2.6 - and WSL Ubuntu - Sigil 2.0).

I rewrote the plugin to use QTableView and QAbstractTableModel, partly to learn about Qt's Model/View architecture, partly because I don't think the elision of the text would be a problem here.

I get a weird glitch, only on Windows/PySide6, with both my WrappingCheckBox and QTableView, when word wrap is set to True: there is always a specific width that causes the text to wrap on two lines, but without the cell or QLabel widget expanding to accommodate it all, like in the attached image. If I then resize the window's width by a couple of pixel, the problem disappears one way or another.
This doesn't happen on Ubuntu (where I use PyQt5).

Quote:
Originally Posted by KevinH View Post
It took most of today to work out the little nits.
I am pleased to have given you the opportunity to have so much fun exploring the deepest meanders of Qt.

Jokes aside, if your experiment is shareable without you wasting more time, I could try to reimplement it for my other plugin, otherwise I'll probably just use the WrappingCheckBox approach.
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2025-08-10 182050.png
Views:	18
Size:	20.6 KB
ID:	217417  
wrCisco is offline   Reply With Quote
Old Yesterday, 04:41 PM   #577
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,848
Karma: 6120478
Join Date: Nov 2009
Device: many
I pushed it to my personal github repo;
https://github.com/kevinhendricks/Sigil

You want:

Sigil/src/Dialogs/DeleteFiles.*
Sigil/src/Dialogs/WrapWordAnyItemDelegate.*
And Sigil/src/Form_Files/DeleteFiles.ui

The smarts are in the delegate but had to create my own replacement for built in resizeRowsToContents() using a loop and individual row resizing as that call ignored the delegate completely (had to read the qtableview.cpp source to find that little tidbit out)!

Then had to trigger my routine in resize events and set it initially after the constructor was done (ie effectively what you did with show).

Hope this helps.
KevinH is offline   Reply With Quote
Old Yesterday, 04:46 PM   #578
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,848
Karma: 6120478
Join Date: Nov 2009
Device: many
If you want me to try to create a python version, just let me know and I will take a shot at it.
KevinH is offline   Reply With Quote
Old Today, 10:27 AM   #579
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,848
Karma: 6120478
Join Date: Nov 2009
Device: many
FWIW, to properly handle vertical alignment within the box, I had to borrow code from another Item Delegate example I found on the web. I have tested it and it now works to show the preferred vertical alignment in the row.

I have just pushed this change to WrapWordAnyItemDelegate.cpp to master on https://github.com/kevinhendricks/Sigil

Just in case you are trying something similar.
KevinH is offline   Reply With Quote
Old Today, 01:33 PM   #580
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
Posts: 850
Karma: 3341026
Join Date: Jan 2017
Location: Poland
Device: Various
@wrCisco: @wrCisco: If you import iswindows:

Code:
from plugin_utils import PluginApplication, QtWidgets, QtCore, Qt, iswindows
…and then an additional attribute:
Code:
    mdp = True if iswindows else False
    app = PluginApplication([], bk, app_icon=PLUGIN_ICON, match_dark_palette=mdp)

then under Windows windows will automatically support dark mode.

Recommended!

Click image for larger version

Name:	sigil-wrcisco-dark.png
Views:	7
Size:	64.0 KB
ID:	217446
BeckyEbook is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 05:48 PM.


MobileRead.com is a privately owned, operated and funded community.