Qt app text size incorrect under MacOSX - c++

Designing UIs with QtCreator under Windows, and porting the same .ui file under MacOSX leads to designs with some text parts very small -- actually, the HTML ones. It seems it comes from the fact that QtCreator uses pt instead of px as text size unit, and that the default screen resolutions are quite different under Windows and MacOSX.
Is there any reason I didn't come to more consistent results? Apart from editing each pt into px, are there any workaround?
Thanks.

As a rule of thumb you should not specify the font sizes for controls manually in Qt Designer/Creator as this leads to the prolems you have. The reason for inconsistency is the fact that different platforms use different DPI settings (96 dpi on Windows vs. 72 DPI on Mac OS X).
This results in fonts being displayed with different sizes.
Also, you mentioned HTML. I assume you have set some HTML text in a QTextEdit-like widget using the built-in editor. When you select a font size there, Qt Creator will produce some HTML like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans'; font-size:11pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Hello World</p></body></html>
As you can see, it sets some font-size attributes, which is really nasty. A simple, easy solution to this desaster is to remove the style= attributes entirely. This causes the QTextEdit to use the default application font instead (which should be fine on all platforms):
<html><head></head><body><p>Hello World</p></body></html>
As a sidenote, this is much friendlier for translators, as they don't have to fight through all the useless CSS.
Unfortunately Qt's QTextEdit does not support the "percent" font-size specification (just px and pt). If it did, you could have used something like "90%" to make the text smaller than the default font while still being on the safe side.
Another option would be a QWebView, which you make editable. This allows for good text formatting while having the full CSS subset. But that might be overkill.
Hope that helps!

Do you have to set text properties in you .ui files? Usually when you set the text property of a widget then UIC replaces completely the Font of that widget with something that it creates from scratch in code. If you edit them on windows then the font will have a windows related name which might cause problems on the mac.
What I usually do is not to touch the fonts in the designer so that the widgets get their defaults fonts which usually look fine and change them in the c'tor of the widget like so:
QFont f = ui.someLabel->font(); // get the current (default) font from the widget
f.setBold(true); // change only what's need to be changed
ui.someLabel->setFont(f);
// set the new and impreved font back to where it came from
This way you can avoid messing with anything that is platform specific.
If your change is actually platform specific you can choose the right one with the use of #ifdef Q_OS_WIN32 or #ifdef Q_OS_MAC

Related

NSIS - Default Installer Width/Height

i have several setups created with nsis (modernui).
Is there any possibility to change the default width/height of the installer?
Regards and thanks,
Dennis
The NSIS UI is actually a main dialog window with a inner dialog where the page content is displayed:
If you want to display multiple pages then you pretty much have to accept this design and use a 3rd-party tool like Resource Hacker to redesign the dialogs. If you want to do this then you should create a copy of "NSIS\Contrib\UIs\modern.exe" and edit it, then use the ChangeUI instruction to select the new UI file (!define MUI_UI yourfile.exe (and possibly the other MUI_UI_* defines) when using the MUI).
On the other hand, if you are developing a autorun splash screen or something like that then you could resize the inner dialog so it covers the whole outer dialog area.
There is no simple attribute that just sets the desired width and height because all controls on all pages also need to be resized and moved...
Have a look at this tool: Graphical Installer for NSIS (a little self promo :)
This tool is capable of changing dimensions of installer + has a lot of other features like installer skinning and many more.

Hiding a sizer and all its contents in wxWidgets using XRC

I am using an .xrc file to setup my wxWidgets GUI. For most GUI elements I can specify <hidden>1</hidden> and the element will not be drawn.
What I'd like is to be able to hide my wxStaticBoxSizer and have it and its contents not be drawn.
It's set up as follows, but adding <hidden>1</hidden> does not have any effect. The static box still draws as does everything it contains.
<object class="wxStaticBoxSizer" name="wxID_ANY">
<orient>wxVERTICAL</orient>
<label>Flight Formation</label>
<object class="sizeritem">
<flag>wxGROW|wxALL</flag>
<border>10</border>
<option>1</option>
Is it possible to hide this wxStaticBoxSizer from the .xrc file?
Quick hack: nest the sizer inside a wxPanel and hide the panel.
If you're willing to rebuild the XRC lib, here's a quick patch that will provide the functionality you need.
In src/xrc/xh_sizer.cpp, in the body of wxSizerXmlHandler::Handle_sizer(), add the following right after the call to CreateChildren(parent, true/*only this handler*/);:
// This has to be done after CreateChildren().
if(GetBool(wxT("hideitems"), 0) == 1)
sizer->ShowItems(false);
That's it. Rebuild the lib, and now you can specify <hideitems>1</hideitems> on a sizer, which means it will be created with all its items hidden.
This will handle all sizers except wxStdDialogButtonSizer, which has separate code. I tested it for wxBoxSizer and wxStaticBoxSizer using the XRC sample. I think I'll send a pull request to add this feature to wx; in the mean time, if anyone could do some more testing on this using a larger application, that would be great.
There is no way to hide the sizer in the XRC currently, the best you can do is to call wxSizer::ShowItems() from the code. It probably would make sense to support the "hidden" attribute for the sizers too in the future, although it should probably be called something else to avoid creating the erroneous impression that sizers are windows (which they aren't).
BTW, if you tried to validate your XRC, you would have found out that "hidden" element is not allowed here.

how can change tittleBar button like close and minimize button in Qt QWidget

i want to change style of QWidget tittleBar button like close and minimize in windows but there is no similar stylesheet elements.
i am using Qt5.1 and windows7.
can any body help me?
If you are talking about how to do this windows, you can do:
this->setWindowIcon(QIcon(":myiconfile.png"));
You will have to add the file in your resources.
You can set the window icon on your widget as per documentation with the following property:
windowIcon : QIcon
This property holds the widget's icon.
This property only makes sense for windows. If no icon has been set, windowIcon() returns the application icon (QApplication::windowIcon()).
So, your code would look like something like this:
myWidget->setWindowIcon("/path/to/your/icon/file");
The icon file path can be relative and absolute as well as one coming from the resource system. The easiest way to test it quickly is just to use the absolute path, but if you plan to ship assets with your application to be self-contained, then you can use resource file with the resource system.

Android ActionBar actionBarSize (bar height) does not work in Portrait Mode

To briefly explain my goal : I'm building an app to a public terminal on android. I'm trying to avoid the top finger pull Status/Notification Menu by the android os. I have not been able to prevent this Menu mechanism programmatically. To accomplish this goal, I'll have a custom made enclosure that'll cover top part of the screen for the android device. Enclosure will also cover home, back buttons.
I'm using android ActionBar (not Sherlock). Obviously the ActionBar tabs needs to move down a little to make room for the covered part by the enclosure. I set paddings for the actionbar through Theming.
Here is corresponding part of /res/values/themes.xml (AndroidManifest.xml is already set to use CustomTheme)
<style name="CustomTheme" parent="AppBaseTheme">
<item name="android:actionBarTabStyle">#style/MyActionBarTabStyle</item>
<item name="android:actionBarSize">#dimen/action_bar_default_height</item>
</style>
<style name="MyActionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:paddingTop">#dimen/actionbar_paddingtop</item>
</style>
This works as expected in landscape mode. In portrait mode paddingtop will work, but action bar height will not adjust (actionBarSize don't work), so the ActionBar tab text will get cut off.
At first I tought dimen files could be the problem. I've tried generating /res/values-port copies of themes.xml and dimens.xml, but doesn't seem to be the problem. padding works after all. I've also tried putting in direct values like 90dp for actionBarSize, and 32dp for padding without any luck.
To me it appears portrait mode does not like actionBarSize. There is no similar question on the web related to this issue, maybe I'm missing something simple. Any help is appreciated.
This may be already too late to answer your question. I will just put this here.
Apparently, this is a bug from android sdk, check this link.
https://code.google.com/p/android/issues/detail?id=41792

How to customize the title bar of a Qt app through Qt stylesheet?

I'm able to customize the controls of a Qt app in a Qt stylesheet. However, I couldn't find a way to customize the title bar. I found some solutions but that requires modifying the code of the app itself. Is there anyway you could customize it using just the Qt stylesheet?
Title bar isn't a part of your application or Qt and it cannot be configured with stylesheet. Title bar is provided by Window manager. In some WMs there is no title bar at all. Most WMs support customisable themes for window decoration. Usualy you can configure you WM to display specific window with specific theme.
In Qt only QDockWidget's title bar can be configured by stylesheet.
P.S. Some applications disable decoration from window manager and draw title bar itself (example Chromium).
Qt has no control over the appearance of the title bar and border of an application. This is the realm of the Window Manager (WM) in use. Qt can ask the WM to turn it off or only display certain buttons, but that's the extent of it.
The standard procedure for a customized title bar is to remove it, and then create and style your own take on the title bar in its place. To anyone watching, please note that this isn't as cool as you think it is. Some people like to customize their titlebar, most people like it when their application blends in with the rest of their operating environment (which it won't when you're done with it).
Short answer: there's no way to do this to an existing application using Qt stylesheets without changing the application's source code.