search

Home  >  Q&A  >  body text

c++ - QT纯手工布局GridLayout

不用Designer设计界面,纯手写代码的话,怎样直接用GridLayout设计下面这样的布局?
我的问题主要是图中label_6label_7怎样居中?

P.S.
我知道可以先用水平布局再用垂直布局,但是能否直接用GridLayout做出来?
另外:

setRowStretch(int row, int stretch)
setColumnStretch(int column, int stretch)

这两个函数的意思是什么?我试了一下也没看出个所以然来……

巴扎黑巴扎黑2804 days ago588

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 11:30:45

    setRowStretch is to set the ratio of the row height to the total row height.
    For example, there is a gridlayout with 4 rows. If you want their row height ratio to be 1:3:5:7, set it like this:

    setRowStretch(0, 1);
    setRowStretch(1, 3);
    setRowStretch(2, 5);
    setRowStretch(3, 7);  
    

    setColumnStretch sets the column width.


    To achieve centering, I usually add two spring controls on the left and right sides of the control, that is, QSpacerItem;
    If I simply use gridlayout to implement a layout like the one shown in the figure, I don’t have a good solution for the time being. My usual approach is to use table layout and put a horizontal layout<🎜 in the row that needs to be centered. >, then put the required controls in the horizontal layout and center the controls.

    reply
    0
  • Cancelreply