PDA

View Full Version : Remove a single arrow in a QSpinBox



WereWind
21st March 2016, 16:04
I develop for Qt 4.8 and I'd like to have a QSpinBox (actually QTimeEdit but I don't think it's a big difference) with a single downwards arrow in the right-middle part.
I tried using stylesheets but I've run into some problems.
When I write
QTimeEdit::up-arrow {width: 0;} I get a square featureless button above the downward arrow. If I try to remove it by adding
QTimeEdit::up-button {width: 0;} the button above disappears but the downward arrow turns into a rectangular button. Other manipulations with stylesheets have failed to provide anything better.
Is there a way to solve my problem?

d_stranz
22nd March 2016, 17:30
Seriously? You want to implement a spin box that can move only in one direction? What if the user clicks one time too many? There's no way to say "oops, I need to go back one click".

It should seem obvious why you can't accomplish what you are trying to do with style sheets.

WereWind
22nd March 2016, 19:04
Well, first of all, there is a way - either by pressing up on the keyboard or scrolling the mouse wheel.

Second, I don't want to move at all. Pressing the arrow would summon a widget to set the time in TimeEdit (something like calendar widget in the DateEdit). Basically it would be just a decoration on the widget that is convenient to store the data I want.

And thirdly. I can have a QSpinBox with a single down-button by using stylesheets and it would work fine. The problem is that the down-button is ugly and I want a prettier down-arrow that disappears the moment I use the word "button" in my stylesheet. You can try it yourself by using the following code


setStyleSheet("QTimeEdit::up-arrow {width: 0;} QTimeEdit::up-button {width: 0;}QTimeEdit::down-button {width: 16px; subcontrol-origin: border; subcontrol-position: center right;}");

anda_skoa
22nd March 2016, 19:48
That sounds more like you want a button alongside the spinbox and not show any of the spinbox's buttons.

Cheers,
_

WereWind
22nd March 2016, 21:03
That is also a possible solution. However I want hte button to look like the calendar arrow in QDateEdit as much as possible to maintain stylistic integrity and I couln't find a way to make QPushButton work this way. So I tried an approached that lookes like it could have better results.

I there is a way to make QPushButtol look like native downarrow that'd be greatly appreciated

Ginsengelf
23rd March 2016, 07:10
Hi, you can try QStyle::drawPrimitive with QStyle::PE_IndicatorArrowUp or QStyle::PE_IndicatorArrowDown to draw the arrow.

Ginsengelf