Note that there are some explanatory texts on larger screens.

plurals
  1. POpyqt addjust spaces between boxes
    primarykey
    data
    text
    <p>I wrote a small example in pyqt. It paint some text first and add three buttons below. However there is some space under the buttons. How to remove those space?</p> <p>I tried <code>addStrech(1)</code>, but then the text is gone.</p> <p>Here is my code:</p> <pre><code>import sys from PyQt4 import QtGui, QtCore class CardWidget(QtGui.QWidget): def __init__(self): super(CardWidget, self).__init__() self.initUI() def initUI(self): lButton = QtGui.QPushButton("left") mButton = QtGui.QPushButton("middle") rButton = QtGui.QPushButton("right") sometext = DrawText() hbox = QtGui.QHBoxLayout() hbox.addWidget(lButton) hbox.addStretch(1) hbox.addWidget(mButton) hbox.addStretch(1) hbox.addWidget(rButton) WButton = QtGui.QWidget() WButton.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(sometext) vbox.addStretch(1) vbox.addWidget(WButton) self.setLayout(vbox) self.setGeometry(300, 300, 480, 370) self.setWindowTitle('Flashcards') self.show() class DrawText(QtGui.QWidget): def __init__(self): super(DrawText, self).__init__() self.initUI() def initUI(self): self.text = 'some text' self.setGeometry(0, 0, 200, 400) #self.setWindowTitle('Draw text') self.show() def paintEvent(self, event): qp = QtGui.QPainter() qp.begin(self) self.drawText(event, qp) qp.end() def drawText(self, event, qp): qp.setPen(QtGui.QColor(168, 34, 3)) qp.setFont(QtGui.QFont('Decorative', 10)) qp.drawText(event.rect(), QtCore.Qt.AlignCenter, self.text) def main(): app = QtGui.QApplication(sys.argv) ex = CardWidget() sys.exit(app.exec_()) if __name__ == '__main__': main() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload