0
GUIアプリケーション内でボタンとメニューバーを取得しようとしています。コードを実行すると、メニューバーにGUIが表示されますが、ボタンは表示されません。ここに私のサンプルコードです。コードはエラーなしでコンパイルされます。PySideを使用したGUIの開発
import sys
from PySide.QtGui import *
from PySide.QtCore import *
class guiwindow(QMainWindow):
def __init__(self):
super(guiwindow,self).__init__()
self.menubar()
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)
self.setGeometry(400, 100, 1200, 800)
self.setWindowTitle("Menubar + Buttons")
button = QPushButton("Test")
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(button)
self.setLayout(hbox)
self.show()
def main():
app = QApplication(sys.argv)
ex = guiwindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
詳細を知るには、適切なチュートリアルやドキュメントを教えてください。これは動作しますが、ボタンがメニューバーの[ファイル]オプションに重なっているように見えます。あなたの答えをありがとう。 –
@RaghavendraMGおそらく、メインウィンドウではなく中央のウィジェットにレイアウトを設定する必要があるからです(これはQtでは許可されていません)。したがって、 'self.setLayout(hbox)'ではなく 'textEdit.setLayout(hbox)'でなければなりません。しかし、 'textEdit'を' centralWidget'のように変更することを検討してください。 – cdonts