Issue
When I run the following example, I expect the QListWidget to be positioned below the menubar, but in fact it positions on top of the menubar. The menubar is still present, as can be confirmed by using the Alt-F shortcut to open it.
import sys
from PySide.QtGui import *
app = QApplication(sys.argv)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
menubar = self.menuBar()
exitAction = QAction(QIcon.fromTheme('appication-exit'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit Application')
exitAction.triggered.connect(self.close)
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
QListWidget(self)
def run(self):
self.show()
app.exec_()
MainWindow().run()
The result:
I was not able to fix this problem by using a QVBoxLayout
(I tried both adding the menubar to the QVBoxLayout
and not adding it).
I'm running pyqt 4.11.4, qt 4.8.7, pyside 1.2.4, and Python 3.5.
Any ideas on how to correctly position the QListWidget?
Solution
You can do either:
self.setCentralWidget(QListWidget(self))
Or:
widget = QWidget(self)
layout = QVBoxLayout(widget)
layout.addWidget(QListWidget(self))
self.setCentralWidget(widget)
The latter is probably better, since you will no doubt want to add more widgets.
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.