[SOLVED] remove the space in between the buttons



  • in the form designer, i have a textEdit and 3 buttons with a vertical spacer beside the buttons and a layout to a grid. the space in between the buttons is about 13 pixels. how to remove the space in between the buttons. i have tried this->layout()->setSpacing(0); but that does not work.



  • try set spacing to layout which contains buttons.



  • i have tried ui->pushbutton->layout()->setSpacing(0); which crashes the program at compile time.



  • I guess maxim meant that you create new layout with your buttons inside and sort the spacing in there, not to try setting spacing on the button itself.



  • Because the pushbutton is in a layout, it most probably does not have one.



  • [quote author="Eus" date="1314341521"]I guess maxim meant that you create new layout with your buttons inside and sort the spacing in there, not to try setting spacing on the button itself.[/quote]

    Eus, i don't understand what you are saying. are you saying to set spacing in the form designer. I can't find any spacing settings in there


  • Moderators

    You could go to the properties of the layout that holds your widgets and set contentmargins.



  • All the three people here are saying the same kalster - create another layout VBox HBox or group, with your buttons only. On that new layout create your spacing.



  • Because ui->pushbutton has no layout set. It has to be ui->nameOfTheLayoutContainingTheButtons->setSpacing(0);

    In doubt please post your generated ui code.



  • Lukas Geyer, no properties for setSpacing in ui->nameOfTheLayoutContainingTheButtons->setSpacing(0);. layout()->setspacing does not work.

    here is my ui code
    @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget"/>
    <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>20</height>
    </rect>
    </property>
    </widget>
    <widget class="QToolBar" name="mainToolBar">
    <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
    </attribute>
    <attribute name="toolBarBreak">
    <bool>false</bool>
    </attribute>
    </widget>
    <widget class="QStatusBar" name="statusBar"/>
    <widget class="QDockWidget" name="dockWidget">
    <attribute name="dockWidgetArea">
    <number>1</number>
    </attribute>
    <widget class="QWidget" name="dockWidgetContents">
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0" colspan="3">
    <widget class="QPlainTextEdit" name="plainTextEdit"/>
    </item>
    <item row="1" column="0">
    <widget class="QPushButton" name="pushButton">
    <property name="sizePolicy">
    <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
    </sizepolicy>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </item>
    <item row="1" column="2">
    <spacer name="horizontalSpacer">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>72</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    <item row="1" column="1">
    <widget class="QPushButton" name="pushButton_2">
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </item>
    </layout>
    </widget>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>
    @



  • [quote author="Eus" date="1314342906"]All the three people here are saying the same kalster - create another layout VBox HBox or group, with your buttons only. On that new layout create your spacing.[/quote]

    but i need the textEdit in the layout.



  • lol
    try using "this":http://translate.google.com
    :D

    lukas gave you an example, you don't have "nameOfTheLayoutContainingTheButtons". He is just pointing out to you that you should use that method on the layout which CONTAINS YOUR BUTTONS.



  • i know that Eus. you read my message wrong which was just an example. i have tried ui->dockWidget->layout()->setSpacing(0); which is the name of the dock widget and it is not working.



  • and that is what we all were saying - have you created a LAYOUT in that widget? I don't see QVBoxLayout, QHBoxLayout or QGroupBoxLayout in your ui code.



  • none of those layouts work. i have tried them before. the problem is that the textEdit horizontal width is a lot greater in width when i try these layout. it just does not work for me.

    but i solved the problem. i should have had ui->dockWidgetContents instead of ui->dockWidget. this topic is solved. thank you everyone for the quick replies.


  • Moderators

    Glad you solved it.

    Could you add [solved] in front of your title?



  • i already did. thank you Eddy and Eus for trying so hard to help. :) also, thank you Lukas Geyer for leading me in the right direction.



  • You're welcome :P


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.