PDA

View Full Version : Code for Horizontal spacer



Gary7
14th August 2012, 17:31
I have a QMainWindow with the central widget set as a QTextEdit. I want to add in a horizontal spacer on each side so the screen will look more like a microsoft word doc or something where theres the white page in the center and then a border type thing on the sides.

Is there a way to do this?

thanks

ChrisW67
14th August 2012, 23:37
To place unused space left or right of the text edit put the QTextEdit into a QHBoxLayout and use one of the functions addSpacerItem() , addSpacing() or addStretch() to add spacing.

Gary7
15th August 2012, 04:52
alright awesome thanks! This might be a dumb question but this is opened from another window and when I try to use setLayout it tries to set it on the original window so I tried making a QMainWindow and setting the layout for that but it wont work, it says that QMainWindow already has a layout. Do you know how I can make a new window pop up and still use QHBoxLayout?

Added after 1 37 minutes:

nevermind.. I used a QWiget instead of QMainWindow and it worked.

Thanks Chris