[SOLVED] font.setStrikeOut

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
CVH
Premier Member
Posts: 3418
Joined: Wed Sep 27, 2017 4:17 pm

[SOLVED] font.setStrikeOut

Post by CVH » Fri Sep 11, 2020 1:32 am

Andrew,

I would like to use a strike out font for the text of a QRadioButton on a dialog.
On top off being enabled / disabled the strike out tells there is no selection at all.

Got this far:

Code: Select all

The Dialog and Widgets and the flag 'hasSelection'
    var dialog = WidgetFactory.createDialog(Tile2Hatch.includeBasePath, "Tile2HatchDialog.ui");
    var widgets = getWidgets(dialog);
    var hasSelection = true; // or false
// The radio button:
    widgets["RunT2HExport"].setEnabled(hasSelection);
    
// None of these alter the font and do not throw an error: 
    widgets["RunT2HExport"].setStrikeOut = true;
    widgets["RunT2HExport"].setStrikeOut = false; // In case it was set in the UI
    widgets["RunT2HExport"].font.setStrikeOut(true);
    widgets["RunT2HExport"].font.setStrikeOut = true;
    widgets["RunT2HExport"].font.setStrikeOut(false); // In case it was set in the UI
    widgets["RunT2HExport"].font.setStrikeOut = false; // In case it was set in the UI
    widgets["RunT2HExport"].font.setStrikeOut(hasSelection);

// Without the .font. and with arguments it throws an error.
// widgets["RunT2HExport"].setStrikeOut(true);
// Other trials fail too
Can you advice me if it is even possible.

Thanks,
CVH
Last edited by CVH on Sat Sep 12, 2020 8:08 am, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: font.setStrikeOut

Post by andrew » Fri Sep 11, 2020 8:48 pm

I think what's happening here is that widgets["RunT2HExport"].font hands you a copy of the widget font. Changing that copy has no effect.

Try this:

Code: Select all

var font = widgets["RunT2HExport"].font;
// change the font here...
widgets["RunT2HExport"].font = font;

CVH
Premier Member
Posts: 3418
Joined: Wed Sep 27, 2017 4:17 pm

Re: font.setStrikeOut

Post by CVH » Sat Sep 12, 2020 7:04 am

Andrew,
that doesn't it either.
Among dozens of other trials and online resources ...

Set or not set striked out in the UI
A widgets["QRadioButton"].font returns:
"MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0"
with a sub class '_proto_'

FontSub.png
FontSub.png (13.74 KiB) Viewed 3541 times

And that class with 59 sub classes going from again '_proto_' to 'wordSpacing'.
Among them: strikeOut & setStrikeOut
So, the setStrikeOut is a sub-sub class and I don't know how to ... and all fails to address that.

FontSubSubs.png
FontSubSubs.png (15.45 KiB) Viewed 3541 times

The same is true for the widgets:
widgets / the 'QRadioButton' / font / _proto_ / 59 sub classes

BTW: '_proto_' that is with twice a double underscore I presume?
One can't distinguish that very good.

Eventually I can drop the whole idea.
But it bugs me that I can't address it as it seems that easy.

Regards,
CVH

CVH
Premier Member
Posts: 3418
Joined: Wed Sep 27, 2017 4:17 pm

Re: font.setStrikeOut

Post by CVH » Sat Sep 12, 2020 7:32 am

This one gives a totally different error that was quite new to me:
widgets["RunT2HExport"].font.__proto__.setStrikeOut(true);
->TypeError: QFont.setStrikeOut(): this object is not a QFont
CVH

CVH
Premier Member
Posts: 3418
Joined: Wed Sep 27, 2017 4:17 pm

Solved: font.setStrikeOut

Post by CVH » Sat Sep 12, 2020 8:07 am

Ok got it,

Sorry Andrew, it might have been a typo or the order of things.

I ran my latest trials again, isolated to document the newer error messages.

Your solution works fine ... now. :oops:

Code: Select all

    var radioButtonFont;

    radioButtonFont = widgets["RunT2HExport"].font;
    radioButtonFont.setStrikeOut(true);
    widgets["RunT2HExport"].font = radioButtonFont;

    radioButtonFont = widgets["PreT2HActions"].font;
    radioButtonFont.setStrikeOut(false);
    widgets["PreT2HActions"].font = radioButtonFont;

// Starting the dialog the strike outs are set/cleared
Thanks for the assistance.
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”