Solved Why setHorizontalSpacing() is not working?
-
I have a QT Application that uses a
GridLayout
. I want to decrease the spacing between the widgets but it doesn't. If I setglay1.setHorizontalSpacing()
to60
then it increases the space, but if I want to decrease it then it's not working :(Here is the code below:
right = QtWidgets.QWidget(label) right.setStyleSheet("""border: none;""") right.setContentsMargins(16, 16, 0, 0) glay1 = QtWidgets.QGridLayout(right) glay1.setSpacing(18) glay1.addWidget(vtext, 0, 0) # the SERVICE text glay1.addWidget(vtext1, 1, 0) # the home icon glay1.setHorizontalSpacing(0) glay1.addWidget(butt1, 1, 1) # the Home text
The following code will give the output:
I want to decrease the space between the home icon and button. What I am doing wrong here?
-
@Abhay-Salvi
Further to my learned colleague @jsulm 's remark. Have a look at overloadvoid QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())
, https://doc.qt.io/qt-5/qgridlayout.html#addWidget-2, which would allow you to span theSERVICES
label across two columns so that the HOME text can move closer to its label.A separate matter is whether you need a grid layout here for what you are going to do with further items. A list of items with icons, or even a menu with icons, might be more appropriate.
-
@Abhay-Salvi This is because of the SERVICE label which takes some space, so first column has a minimum width of SERVICES label.
-
@Abhay-Salvi
Further to my learned colleague @jsulm 's remark. Have a look at overloadvoid QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())
, https://doc.qt.io/qt-5/qgridlayout.html#addWidget-2, which would allow you to span theSERVICES
label across two columns so that the HOME text can move closer to its label.A separate matter is whether you need a grid layout here for what you are going to do with further items. A list of items with icons, or even a menu with icons, might be more appropriate.
-
@Denni-0 Thanks for your answer :) I got it