[solved] adding combo box to existing program
-
I am learning Python/Qt, partly by combining examples.
I have a working program which contains a graph and a couple of thermos.I downloaded a standalone example of a combo box, and that runs OK.
When I try to insert it into the program, however, the program does not run.If I comment out lines 50 and 72, which I expected would include the combo box,
the program runs, without showing the box.I expect that I am missing something simple, but have been trying everything that
I can think of, and would appreciate if someone could take a look at the code.
As the whole program is too large, I will show only the parts which I hope are relevant.@
import math
import sys
from PyQt4 import Qt
from PyQt4 import QtGui, QtCore
import PyQt4.Qwt5 as Qwt
import numpy
import time( code removed)
class ComboBox(Qt.QWidget):
def __init__(self, title, parent): self.vbox = QtGui.QVBoxLayout() self.setLayout(self.vbox) self.combo = QtGui.QComboBox() self.vbox.addWidget(self.combo) self.lbl = QtGui.QLabel('Ubuntu') self.lbl.setAlignment(QtCore.Qt.AlignHCenter) self.vbox.addWidget(self.lbl) distrolist = ['Linux Mint', 'Gentoo', 'Mandriva'] self.combo.addItems(distrolist) self.connect(self.combo, QtCore.SIGNAL('activated(QString)'), self.combo_chosen) def combo_chosen(self, text): self.lbl.setText(text)
(code removed)
class AmplifierFrame(Qt.QFrame):
def __init__(self, *args): Qt.QFrame.__init__(self, *args) self.phs = 0.0 self.master = 0.0 self.leftThermo = Thermo('Left [dB]', self) self.rightThermo = Thermo('Right [dB]', self) layout = Qt.QHBoxLayout(self) layout.setSpacing(0) layout.setMargin(20) layout.addSpacing(2) layout.addStretch(0)
layout.addWidget(self.combo)
layout.addWidget(self.leftThermo)
layout.addSpacing(10)
layout.addWidget(self.rightThermo)class MainWindow(Qt.QWidget):
def init(self, reader=None, *args):
Qt.QMainWindow.init(self)
self.setWindowTitle(" scope")
self.resize(800, 600)# register the reader if reader is None: self.reader = DefaultReader() else: self.reader = reader accel_data = AccelData(self.reader) timescope = TimeScope(accel_data)
self.combo = ComboBox('X-axis', self)
amplifierFrame = AmplifierFrame(self) amplifierFrame.setFrameStyle(Qt.QFrame.Panel | Qt.QFrame.Raised)
layout = Qt.QHBoxLayout(self)
layout.setSpacing(20)
layout.setMargin(40)
layout.addWidget(amplifierFrame)if name == 'main':
app = Qt.QApplication(sys.argv)
form = MainWindow()
form.show()
sys.exit(app.exec_())
@