Qt draws text with otf font outside the element - c++

Today I switched the font of my application from one of the standard system fonts to Sinkin in the form of an otf file, I've added to my resource.qrc.
The following code sets the default font of the application object.
int id = QFontDatabase::addApplicationFont(":/fonts/font.otf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
qapp.setFont(family);
QFont font = qapp.font();
font.setPointSize(opt_font_size);
qapp.setFont(font);
Now it seems, that the font is placed a bit too high in all elements. That means buttons, labels, input fields and tabs. Or Qt does not realize, that it has to adjust the size of the elements to fit the new font.
Changing the font size via setPointSize does not fix it. Everything just gets smaller or bigger.
Any ideas where I can dig into?

Related

Text alignment issue in Listbox

I'm trying to make a little GUI script using tk. After computation on the basis of user input, I generate a simple string that I want to print using a listbox, but it was suffering from alignment problems.
I tried printing the output in the console at the same time to check whether this was a formatting error:
for loop :
string = foo(x)
listbox.insert(END, string)
print string
The problem is that the console is using a fixed width font but the listbox is using a variable width font. In a variable width font, characters like "i" (lowercase I) and "l" (lowercase L) take up less horizontal space that characters like "M" and "0".
If you want characters to line up in a listbox like they do in the console, you need to use a fixed width font. You can configure the font used by the listbox via the font attribute.
Tkinter provides several default fonts, the default fixed-width font is named "TkFixedFont". This default font will be approximately the same vertical height as the default variable width font that is used by other widgets. The exact font that is chosen may be different on different platforms, but is typically a variant of courier.
For example:
import Tkinter as tk
root = tk.Tk()
listbox = tk.Listbox(root, font="TkFixedFont")
If you wish to be explicit about the font family and size, you can provide that as a string, tuple, or as a font object. For example, picking a courier font of size 18 could be specified as font="Courier 18".
listbox = tk.Listbox(root, font="Courier 18")
For more information on fonts, see the TkDocs tutorial on fonts, colors and images and the section Widget Styling on effbot.

QT Labels overflows when window size get smaller

I am creating an UI for my application using QT. When I change size of my window some of labels are gets cropped.
So what I've tried is
ui.setupUi(this);
QWidget::showMaximized();
ui.statusBar->setSizeGripEnabled(false);
int w = QWidget::width()/10;
int h = QWidget::height()/10;
then using this values I've resize my labels.
However it doesn't work while my software is open and it is not a goodway to do it I think. So I have to dynamically change label sizes in order to keep all items in the window
I've been searching days and days to figure out but still I have no clue.
this is the gui I've created.
and when I change size.
Read up on Layout Management in Qt.

Auto Sizing Labels in Qt

I'm developing a Qt application and it's currently in an internal beta test. One member of the company has Windows configured to display text larger than its normal size, which breaks my UI. The About page, for example, currently looks like this:
but under his settings, looks like this (note the clipped text):
Coming from a C#/Winforms background, I'm amazed that I can't seem to find some easily configurable label property such as Form.AutoSize that will automatically size the labels to fit their containing text. I've tried messing with sizePolicy, scaledContents, and a few other properties, but none seem to do this.
I've come across various threads (such as this one) which give instructions for scaling the text to the label, but I want to do the opposite - scale the label to the text to facilitate for those with enlarged text settings like my co-worker. Is there a straightforward way to do this?
There are at least three solutions to this problem.
Use layouts. Their contents are scaled according to the size of the window.
Make a code which is executed whenever window size is changed. In that code, you get the width of the longest text in the window (How?)(another way) and then set window wider than that.
Do the same as in solution #2, but execute the code only when the dialog is shown. After that, alter the window properties so that its size cannot be changed.

C++ Win API Specify Custom toolbar Bitmap?

Picture and c++ files can be found here: http://phantomworksstudios.com/cpp/ss/
Ok so I have been having a lot of problems with my toolbars. such as them not displaying correctly, can't set the button size via height and width no matter what I do, the bitmaps are off set by 1 pixel to the right which are the back,forward,stop, etc icons. and the other icons such as the clip board and new file which is the last tool bar under the rest are cut off bad. I think its still trying to strip the tool bar list as 16x16 but the bitmap I have icons as 14x14.
The icons are within a bmp file which is 32 bit depth
one is 16x16 while the last one is 14x14
I have no idea what is going on and no matter what I can't seem to get it working like it should:

Qt QLabel HTML font size fails badly

In my Qt application (uses Qt 4.7.0 from Ubuntu 10.10 Linux repository) i tried to use Qt::RichText QLabels using the following HTML:
label_1->setText("<font size=64>size=64</font>");
label_2->setText("<font color=red size=10>size=10</font>");
label_3->setText("<font color=blue size=14>size=14</font>");
For some reason the font sizes are not set properly. All the widgets get the same font size, one that is larger than the default one but still the wrong one. The font size set for the first widget seems to influence the size that the following widgets will use. Setting only the color attribute leaves the label text in its standard size.
I also tried to reproduce this in the QtDesigner and the same problem happens there.
Setting the text format to Qt::Richtext does not have any effect. And using quotes around the HTML attribute values does not change anything either.
What am I missing?
Okay, so font size is supported but have you tried CSS-style font-size:64pt? CSS is better because the size has explicit units.