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

grid solver constraint not working #2566

Open
marcel-goldschen-ohm opened this issue Jan 6, 2024 · 4 comments
Open

grid solver constraint not working #2566

marcel-goldschen-ohm opened this issue Jan 6, 2024 · 4 comments

Comments

@marcel-goldschen-ohm
Copy link

I'm having similar issues to #1268 , but the subgrids are not an appropriate solution for me. I'm trying to roll my own constraints with Kiwisolver but they are not working (see example code below). Perhaps someone can tell me what I am doing wrong.

In the following code I am trying to simply constrain two side-by-side views so that one is always twice as wide as the other. However, this code results in two equal width views. Any help would be appreciated.

app = QApplication()
canvas = scene.SceneCanvas()
canvas.native.show()
grid = canvas.central_widget.add_grid()
view0 = grid.add_view(row=0, col=0, bgcolor='red')
view1 = grid.add_view(row=0, col=1, bgcolor='green')
# attempt to constrain view0 to be twice as wide as view1
# note: I've tried different strengths (e.g., 'strong') and without a strength, makes no difference
grid._solver.addConstraint((view0._var_w == 2 * view1._var_w) | 'required')
print(grid._solver.dumps())  # the constraint is listed as expected
grid._solver.updateVariables()
canvas.update()
app.exec()
# result is view0 and view1 have equal widths :(
@djhoese
Copy link
Member

djhoese commented Jan 6, 2024

Doesn't row_span and col_span passed to the add_view method perform this same type of behavior?

Unfortunately there isn't anyone in the current maintainer group that understands kiwisolver or how this stuff works. Additionally, you'll have trouble (like you are already) hacking the solver as I believe any time widgets are updated the constraints may be reset. On top of that, even if you get the solver to be what you want doing canvas.update() may not be enough to force the widgets to use the new geometry constraint results. That's just a guess though.

@marcel-goldschen-ohm
Copy link
Author

In this simple case col_span might work, but it won't for my use case involving a less simple grid with some fixed width/height elements.

That's truly unfortunate. It would be really useful to be able to supply user constraints to the layout.

@djhoese
Copy link
Member

djhoese commented Jan 7, 2024

There's always a chance that it will work in some way, but I'm not sure there is anyone here that can help so it may come down to printing out the current solver state yourself. There may be other methods on the ViewBox that would trigger/force an update or you could maybe tell the Canvas to "resize" to the same size and that might trigger the updates properly. Off the top of my head though I'm having trouble coming up with an easy solution.

@marcel-goldschen-ohm
Copy link
Author

Thanks @djhoese . If I find the bandwidth to dig into this, those are some good suggestions.

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

No branches or pull requests

2 participants