Solved QHBoxLayout, QVBoxLayout, QBoxLayout or other?
-
Hi
Did you check out
http://doc.qt.io/qt-5/qformlayout.html#detailsits what i often use for xxx | yyy layouts.
-
@mostefa , @mrjj
Thanks for suggestions, will investigate.Could you just comment on: if code does use
QVboxLayout
parent + multiple-QHboxLayout
children, and theQHBoxLayout
s each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up? I.e. does Qt left to itself do anything about making siblingQHBoxLayout
s have same column widths? Otherwise perhaps in existing code they are just divided up like 50% each for two, so they line up, or perhaps existing code sets fixed widths? -
@JNBarchan said in QHBoxLayout, QVBoxLayout, QBoxLayout or other?:
if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up? I.e. does Qt left to itself do anything about making sibling QHBoxLayouts have same column widths?
if code does use QVboxLayout parent + multiple-QHboxLayout children, and the QHBoxLayouts each have multiple (but same number of) widgets added to them, do the "columns" of child widgets actually line up?
No, there is no automatic alignement in this case , you can achieve a good alignement , but you have to play with (column stretch , row stretch...)
Trust me using QGridLayout , or QFormLayout will offer you more comfort , by using one of them you can maintain your code more easily in the future.
-
@mostefa
Thanks, that (lack of alignemnt in separateQHBoxLayout
s) confirms what I suspected.I will indeed look at using
QGridLayout
/QFormLayout
for new code I write. My question was because I wonder how the existing code has achieved columnar layout using onlyQV/HBoxLayout
, when i don't fancy trawling through it all to understand. I have a feeling it might be using fixed-width columns on eachQHBoxLayout
and that's how they achieved the alignment, but it doesn't matter going forward. -
@JNBarchan my two cents worth is to use the form layout. The code you mentioned, if it didn't use forms or grids, probably used some other constructs (like setting fixed sizes) to get the alignment you saw. Anyway, forms are meant for just what you're doing. Grids would be fine too.
-
OK then in that case, anyone care to summarize the difference of
QGridLayout
versusQFormLayout
, e.g. which one is one more lightweight for my presumably minimal needs? -
@JNBarchan well QFormLayout is a two-column layout designed for input devices and their labels...seems precisely right for you. QGridLayout is more general purpose. In actuality, I'd expect the difference in coding effort and performance to be minimal, but you might as well use something that's tailor-made for your purpose.
-
designed for input devices and their labels
By "devices" do you mean "controls/widgets"?I think you're saying
QFormLayout
is for:Label1 Input1 Label2 Combo2 Label3 Checkbox3
I see the point of that. Funnily enough, though, although I (presently, but might change) do have 2 columns, it's a bit different here, it's something like
Button1 Explanatory text of why you might like to click the button :) Button2 Explanatory text ....
Since I'm not really sure what I might end up with, but I know there will be columnar alignment required whatever, I might rather look into
QGridLayout
.... -
Yes, you did a better job wording it than I did. If you need the option of adding additional columns, then you'll want to use QGridLayout.
-
Slightly off topic, but if all you want to display is an explanation of the proper usage for the button, why not use a tool tip? That's what a tool tip is supposed to do without taking up screen real estate.
-
@mranger90
Because my stakeholders/users demand an on-screen explanation in this context. (Screen estate is not limited because this is the totality of this page.) Because they are fussy, pampered users who won't look at a tooltip (won't even see it --- "You mean I have to move the mouse?") and will moan if the layout is not exactly what they have decided they want, claiming they cannot possibly know what the buttons might do.Not nice friendly, co-operative, open-minded, tolerant developers.
Get the picture? ;-)