Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeSlider doesn't obey "stretch" in line layouts #3696

Open
jamshark70 opened this issue Apr 25, 2018 · 2 comments
Open

RangeSlider doesn't obey "stretch" in line layouts #3696

jamshark70 opened this issue Apr 25, 2018 · 2 comments
Labels

Comments

@jamshark70
Copy link
Contributor

@jamshark70 jamshark70 commented Apr 25, 2018

The two Sliders (lower view) have different heights, according to stretch factors.

The two RangeSliders look the same. Why? I think, bug.

(
w = Window("test", Rect(800, 200, 300, 200)).front;
w.layout = VLayout(
	View().background_(Color(0.5, 0.5, 1.0))
	.layout_(VLayout(
		[a = RangeSlider().orientation_(\horizontal), stretch: 3],
		[b = RangeSlider().orientation_(\horizontal), stretch: 1]
	).spacing_(2)),
	View().background_(Color(0.5, 1.0, 0.5))
	.layout_(VLayout(
		[c = Slider().orientation_(\horizontal), stretch: 3],
		[d = Slider().orientation_(\horizontal), stretch: 1]
	).spacing_(2))
);
)
@eleses

This comment has been minimized.

Copy link
Contributor

@eleses eleses commented Mar 26, 2020

The bug is probably here

void QcRangeSlider::setOrientation(Qt::Orientation o) {
    _ort = o;

    if (_ort == Qt::Horizontal) {
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    } else {
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    }

    updateGeometry();
    update();
}

In contrast Slider (which works properly) does:

void QcSlider::setOrientation(int i) {
    _ort = (Qt::Orientation)i;

    if (_ort == Qt::Horizontal)
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    else
        setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);

    updateGeometry();
    update();
}

So I think simply changing QSizePolicy::Fixed to QSizePolicy::Preferred might fix RangeSlider. I need to get myself the Qt toolchain setup so I can actually try this...

@eleses

This comment has been minimized.

Copy link
Contributor

@eleses eleses commented Mar 26, 2020

Workaround for now: make some views and set the size of the RangeSliders as big the views, plus set them to resize = 5.

(w = Window.new.front.layout =  HLayout([a = View(), s:1], [b = View(), s:2]);

x = RangeSlider(a).orientation_(\vertical).resize_(5);
x.bounds_((0@0) @ a.bounds.extent);

y = RangeSlider(b).orientation_(\vertical).resize_(5);
y.bounds_((0@0) @ b.bounds.extent);
)

Given that this works, I suspect the C++ fix I proposed will probably work too. I was afraid that because RangeSlider is custom drawn in SC’s C++ code, i.e. not a built-in Qt class, there might be more stuff to do, but apparently there isn’t.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.