Ruler widget name

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
User avatar
petevick
Premier Member
Posts: 392
Joined: Tue May 19, 2020 9:34 am
Location: North Norfolk coast UK

Ruler widget name

Post by petevick » Sat Dec 31, 2022 7:23 pm

I'd like to add the ability to change the colours for the ruler in Qcad with my theme apps, but I can't find the name of the ruler widget. Searching Github I came across RRuler and RRulerQt, neither of which work, I've also tried QRuler, but again no go. If anyone knows what the name is, or even if it's possible to change the ruler colours, I'd be grateful.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6

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

Re: Ruler widget name

Post by CVH » Sun Jan 01, 2023 12:25 pm

Pete,

Looked into that.
I think it is more then just one setting for one ruler, remember that there are up to 4 viewports with each 2 rulers (or not by preferences).
See Application or Drawing Preferences .. Layout .. Viewports

I did a search too but I perform a textual search with Notepad++ in a full local copy of all the files on GitHub. :wink:

In DefaultNavigation.js I discover that it retrieves HorizontalRuler & VerticalRuler of the presented widget (Probably a viewport).
And that it updates these depending a mouseMoveEvent or for scrolling/panning/zooming with simulateMouseMoveEvent

It resurface in ViewportWidget.js where a viewport widget is created.
The default widget layout is sourced from ViewportWidgetQt.ui
The HorizontalRuler & VerticalRuler of this ui file are nothing but empty space.

All this is very complex, there are several events to listen to, values and tick marks need to be spaced in any user format, on any kind of display.
In fact, it is the essence of how we navigate in a drawing document, what part of the geometry is shown, scrollbars, grid and so on.
It must be clear that this is repainted on almost everything we do in the QCAD GUI.
I then suspect this is handled in C++. :wink:

Searched further and I don't think you can really solve this:
Both rulers of ViewportWidgetQt.ui are of the RRulerQt class ...

RRulerQt.cpp >> RRulerQt::getFont()
The font to draw labels in is always sourced from RSettings (=Preferences).

RRulerQt.cpp >> RRulerQt::paintTick(int pos, bool major, const QString& label)
Line 126 and further: https://github.com/qcad/qcad/blob/1c5e3 ... t.cpp#L126
This paints a single tick mark in the ruler bar and adds some text if provided:

It seems that the colors are hard-coded depending the GUI background e.g.:
painter->setPen(darkGuiBackground==1 ? Qt::white : Qt::black);
A black and then a white mark for the dark theme and reversed on all others.
The second painter then actually draws the label text ifso, and this is not a text or a label field at all.

Regards,
CVH

User avatar
petevick
Premier Member
Posts: 392
Joined: Tue May 19, 2020 9:34 am
Location: North Norfolk coast UK

Re: Ruler widget name

Post by petevick » Sun Jan 01, 2023 4:26 pm

CVH wrote:
Sun Jan 01, 2023 12:25 pm
It seems that the colors are hard-coded depending the GUI background e.g.:
painter->setPen(darkGuiBackground==1 ? Qt::white : Qt::black);
A black and then a white mark for the dark theme and reversed on all others.
That's the conclusion I came to as well
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Qcad Pro 3.29.6

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”