Qt::How to lower the text in a QSpinBox - c++

I'm using a spinbox with a custom font which looks too high in the spinbox. How do I move the text lower?
I have already reimplemented QStyle and made the font lower in another widget but I can't find where to do it with the spinbox. There must be a QRect somewhere where you can just move the top of it but I don't know and can't seem to find where it is.

Qt specifies a QStyle::SC_SpinBoxEditField, which appears to be what you want to modify. If I recall correctly from a few years ago when I was doing stuff with styles, you should be able to hook into getting options for that subcontrol, which would include the rect within which it is supposed to be drawn. Modifying that might get the result you want. If not, it is a place to begin searching for your answer.

This is more of a guess than a positive answer, but you might be able to do this with stylesheets:
spinbox->setStyleSheet("QSpinBox { bottom: -2px;}");
Ideally there would be a subcontrol or something for just the text, but the stylesheet documentation doesn't list one, which might imply the above will have undesirable consequences.

You can do:
spinBox->setAlignment(Qt::AlignCenter);//Or the Align Flag that you want
I hope this help.

Related

How to show checkbox in the top left corner of its multiline text C++

Is there a way to do this? Also, the lower text is truncated when I set it as multiline. Is there a way to increase the size of rect for the checkbox so that the multiline string fits in it.
Thank you very much.
Top is possible.
Left is doubtful. you can try it.
In the below link look for "Text Alignment Styles"
https://msdn.microsoft.com/en-us/library/tf9hd91s.aspx
For setting the style use,
CButton::SetButtonStyle(UINT nStyle,BOOL bRedraw = TRUE)
Look for documentation here in below link
https://msdn.microsoft.com/en-us/library/yf1wax6c.aspx#cbutton__setbuttonstyle
for multiline fit probably you have to set the style to button using "setButtonStyle" with an option "BS_MULTILINE".
Use a CheckBox together with a Static. My experience tells me that this workaround is good for many reasons. (E.g. you can easily make the checkbox look transparent, which would otherwise be excruciatingly hard.)

C++ & Qt : A slider like in Adobe After Effects

I'm quite new to C++ & Qt, but I would like to implement sliders like in After Effects in an opensource project i'm working on.
I mean, not a "visual" slider (a bar, like at the left of the pic), but
a numeric value, which is shown like an hyperlink;
and which change if you click & slide right or left.
You can either slide on it or click it and directly enter the value.
(source: pencil2d.org)
Any ideas ?
I'm no expert either, but this may help you.
It sounds like you want to create your own widget.
Then you should subclass QWidget, reimplement mouseEvents (to make it respond to vertical "drags") and paintEvents(to make it look the way you want it to look), give it the signals you need. If you don't want to start from scratch, maybe sublcassing QLineEdit you gain some steps. Look this trhead, and this tutorial. This last is a real "eye opener", if you take the time to understand it thoroughly. Good luck!

Is it possible to reference individual tabs of a QTabWidget by tab number?

Very quick question here. I was wondering if it is possible for me to reference individual tabs from a QTabWidget by number. This will save me a lot of time, as I am generating an unknown number of tabs during run-time. I could not find anything in the QT documentation, but I feel like this is a very basic feature that should be included. I am thinking something like this (not real code just an idea, I realize tabNumber() doesn't exist):
ui->tabArea->tabNumber(12);
If there isn't a public function, perhaps there's some other way? Please don't suggest referencing tabs by name because that is out of the question (potentially 100's of tabs), and I have already tried it.
If you want the tab with a certain index, use widget():
QWidget* tab = tabWidget->widget( index );
I think the setCurrentIndex() method is what you are looking for.

Determining Qt stylesheet options programmatically?

Is it possible to look up stylesheet values at runtime in Qt?
I'm working on a custom button derived from QPushButton that has some stylesheet properties set. I'd like to be able to look up some stylesheet settings like border width, margin, padding-top, padding-left, padding-right, etc. Is this at all possible to do without calling widget->getStyleSheet() and parsing out the values myself?
Internally, when you call QApplication::setStyleSheet() Qt creates a QStyle sub-class called QStyleSheetStyle.
That means you can query style sheet information via the normal QStyle methods. Just remember to fill in the options and widget parameters properly to ensure you get the right values from the style sheet.
Don't think so, you might be able to find something by stepping through the drawing code. But the parsing and the application of stylesheets is pretty optimised and uses a lot of preprocessing. I don't even think that you can get to the stylesheet of a widget if it was actually set in a parent.

Qt: How to show icon when item selected

I have a QListWidget containing items which have icons and when the items are selected the icon is just highlighted out. Is there a way to prevent this? I can't use stylesheets because it's for an embedded application and including them takes up too much space.
thanks
I suppose when you say "Highlithed out", you mean that the icon colors don't render well when the line is selected, and therefore, you can't see properly the icon...
Maybe you could consider using a different icon when the item is selected. It's possible to do so by specifing a mode to your icon.
Example :
QIcon MyIcon(":/images/foo");
MyIcon.addFile(":/images/bar", QSize(...), QIcon::Selected);
You can easily make a try in QtDesigner and see the results...
Hope it helps a bit !
Certainly, drawing on a black-and-white screen presents its challenges.
It sounds like you just want to change the appearance of the interface, not any functionality. If this is the case, a QItemDelegate-derived class (or QStyledItemDelegate) is almost certainly what you want. In particular, the drawDecoration function looks like it is used to draw an icon, and the style options should include whether it is selected. The simplest fix would be to override that function, set the selected flag in the options to false, then pass it up to the parent's function.