1

I have read the documentation on the following matter, but QtGui is so overwhelmingly complex I might have missed the piece.

I have created a GUI, in which it consists of a menubar two QLabel and two QLineEdit and a button. The issue I am facing in my code is the button is getting placed on an absolute co-ordinate position and does not dynamically resize according to the window resizing and the QLineEdit box is displayed with a certain horizontal shift from the QLabel. But I would like to place it next to the QLabel. I have attached a pic of the GUI which I am getting. Here is my code

import sys
from PySide.QtGui import *
from PySide.QtCore import *

class guiwindow(QMainWindow):

    def __init__(self):
        super(guiwindow,self).__init__()

        self.central = QWidget()
        self.setCentralWidget(self.central)

        self.setGeometry(400, 100, 1200, 800)
        self.setWindowTitle(" Automatic Selector")            

        self.menubar()
        self.makebuttons()
        self.angles()

    def menubar(self):
        textEdit = QWidget()
        self.setCentralWidget(textEdit)

        exitAction = QAction('Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(self.close)
        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAction)

    def makebuttons(self):
        # self.central_widget = QWidget()
        # self.setCentralWidget(self.central_widget)

        button = QPushButton("Test", self)
        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(button)
        # self.central_widget.setLayout(hbox)
        self.show()

    def angles(self):

        self.window = QWidget()
        self.setCentralWidget(self.window)

        self.Rotation = QLabel('Rotation:')
        self.Tilt = QLabel('Tilt:')

        self.RotationEdit = QLineEdit()
        self.RotationEdit.setFixedWidth(55)
        self.TiltEdit = QLineEdit()
        self.TiltEdit.setFixedWidth(55)

        self.grid = QGridLayout()
        self.grid.addWidget(self.Rotation,1,0,Qt.AlignLeft)
        self.grid.addWidget(self.RotationEdit,1,1,Qt.AlignLeft)
        self.grid.addWidget(self.Tilt,2,0,Qt.AlignLeft)
        self.grid.addWidget(self.TiltEdit, 2,1,Qt.AlignLeft)
        self.window.setLayout(self.grid)

def main():
    app = QApplication(sys.argv)
    ex = guiwindow()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

And if I take out

self.window = QWidget()
self.setCentralWidget(self.window)

from the def angles(self): the Rotation angle and the tilt angle does not appear on the GUI. Why does this

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Raghavendra MG
  • 89
  • 2
  • 11
  • The `button` is not part of `window`s layout while it is the central widget. You should add the `hbox` to this layout via `addLayout`. – a_guest Jan 16 '17 at 21:25

0 Answers0