Vertically align components by baseline in a QHBoxLayout - macos

I'm using Qt Designer to lay out a form with QLabel, QLineEdit and QComboBox controls inside of QFormLayout and QHBoxLayout containers. What do I need to do to have the controls aligned vertically by their text's baselines?
When previewing the dialog on Max OS X, the different controls do not align by their baseline. The following example is using QHBoxLayout, but the same happens with QFormLayout:
Notice how the underscores are not on the same vertical position.
I'm looking for a solution that will work with all widget combinations where baseline adjustment is applicable and where the adjustment is done automatically based on style, platform, widget combination, widget sizes and font settings. Something comparable with CSS's vertical-align: baseline;.
Update
I've done the same test on Windows XP and also applied RA.s suggestion of using a style sheet. But that does not seem to change any of the placement of the controls or their text.

If I understand your question correctly, you need to change the vertical alignment of the QLabels. In Qt Designer, you can accomplish this by clicking on the QLabel, then adjusting the label's alignment property. In this case, I believe that changing the vertical alignment to AlignBottom might fix your problem. If that doesn't work, the label also has a margin property that you can adjust.
Update
Consider using Qt's style sheets for your application. The following style sheet achieved the desired result on the platforms that I could test on (which, unfortunately, does not include OS X):
QLabel, QComboBox, QLineEdit
{
background-position: bottom;
}

Related

Padding under font only on Mac

My horizontal nav bar and footer look perfect on PC, but when testing on Mac, the font is lifted about 30px above its position in the horizontal nav bar.
After trying every CSS reset and line-height adjustment, what finally worked on Mac made the font drop about 30px below its position in the horizontal nav bar on PC this time.
One Stackoverflow answer mentioned editing the glyph/baseline of a font.
I downloaded a free font editing program and noticed the characters inside of each respective square were lifted as if to have a 40px margin underneath, but I can't adjust the height of the baseline in the program.
Is there a free font manipulation program that will allow me to adjust the glyph/baseline of the font?
I appreciate your time in advance.
Try to generate your font via http://www.fontsquirrel.com/, and use the CSS for font-faces it gave you.
If the above does not work for you, try this:
Try to find out with JavaScript if the app is running on Mac. If so, load a new font-fix-mac.css file, where you will put margin-top:30px on all elements where the font is lifted above.

NSSegmentedControl with bold, italic, and underlined segment

I'm trying to build a segmented control much like the Bold/Italic/Underline control in TextEdit.
Is there a way to set a custom attributed string for each segment? [set attributedStringValue:] on the cell had no effect (there's no way to set per segment anyway).
If I have to resort to custom drawing, how can I reproduce the inset/blue highlight in the selected state?
Example:
I think these are all icons you need to pre-create and set in the segmented control. Custom drawing would be another option, but I think simply using 3 icons (plus their hires variants) is more flexible.
For custom drawing you'd use an NSAttributedString where you set font and color. Draw it twice, once in white with one pixel vertical offset and and once in blue/black.

Aligning text boxes

I'm have some data output text boxes (text boxes with no border and with the same background as the rest of the window) that I'm trying to align with a standard edit control + spin button, to represent a column of numbers, one of which can be edited:
I can manually align these in the Delphi / C++Builder form designer, but when I then view the form on a different version of Windows or at a different DPI, the text is no longer right-justified, presumably because of differences in the spin button spacing, borders, etc.
I can use EM_GETMARGINS to determine the width of the spin button, but how can I determine the size of the edit control's margins and borders? I've tried various combinations of EM_POSFROMCHAR, ClientToScreen, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CXEDGE), and GetThemeMargins, but so far, I can't find a combination that works and makes sense.
More details:
Environment is Delphi / C++Builder XE2.
The data output controls are TEdits with BorderStyle bsNone.
The edit + spin button is a TJvSpinEdit. From viewing its source, it uses EM_SETMARGINS to allow space for its spin button.
Use the Win32 API GetWindowRect() and GetClientRect() methods. The bordering will be the difference between the two rectangles. That will only give you the bordering, though. There could be extra spacing inside the client area.

Make NSToolbar Icon for NSToolbar

I'd like to make an icon for my NSToolbar that has the same system stylings applied to it as the template icons in IB. How do you do this? I can't get the toolbar to apply system stylings like it says it will in the HIG.
Thanks!
In Mac OS X v10.5 or later, images whose name ends in the word "Template" are automatically marked as template images. NSImage Class Reference
NSImage *image = [NSImage imageNamed:#"MyImageTemplate"];
This also works for Interface Builder.
More information: http://www.proppe.org/blog/2007/12/01/nsimage-templates/
If you mean for a monochromatic icon, make sure you set it as a template image. That's what tells the system to render it with the inner gray or blue gradient.
The toolbar doesn't do that automatically. You have to create the graphics yourself. The Lion-style icons are usually mid-gray with a subtle inner shadow and a 1px whitish drop shadow. Here's an example done in Photoshop:
And here's all the layer styling done to it:
The specific numbers and colors may vary depending on the icon's shape and size.
On a side note, the HIG was saying that icons may change depending on the control. For example, when you disable a button, its icon will be displayed semi-transparently.

Glow around Button

How can I draw a slight white 'glow' around a button or label in 10.5 and later? I have seen some apps do it, but I am still confused how I should do this.
See NSShadow. You'd create and set a shadow (saving your graphics context beforehand), then draw the basic shape of your button, unset it (by restoring your graphics context), then continue drawing as usual.
In the case of a ready-made control like NSButton, you will need to subclass and override its cell drawing (and possibly make the host NSButton control itself a bit larger to accommodate the larger area needed to encompass the "glow" of the cell).
You might be able to avoid this with a label by setting its font shadow, but I don't think IB lets you do this, so you'd programmatically give the label an attributed string (via its -setAttributedString: method). The attributes would include the NSShadow (configured as desired) as the NSShadowAttributeName.

Resources