从这组代码开始
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class combodemo(QWidget):
def __init__(self, parent = None):
super(combodemo, self).__init__(parent)
layout = QHBoxLayout()
self.cb = QComboBox()
self.cb.addItem("C")
self.cb.addItem("C++")
self.cb.addItems(["Java", "C#", "Python"])
self.cb.currentIndexChanged.connect(self.selectionchange)
layout.addWidget(self.cb)
self.setLayout(layout)
self.setWindowTitle("combo box demo")
def selectionchange(self,i):
print ("Items in the list are :")
for count in range(self.cb.count()):
print (self.cb.itemText(count))
print ("Current index",i,"selection changed ",self.cb.currentText())
def main():
app = QApplication(sys.argv)
ex = combodemo()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我们的目的是在5个sCylinder中选择并高亮显示:
不知道为啥失败了…折腾了1天…改为以下代码:
sText = qt.QLabel('选择穿刺轨迹:')
self.sSelector = ctk.ctkComboBox()
self.sSelector.toolTip = "选择穿刺轨迹"
screwList = ['Select a trajectory', "cS1","cS2","cS3","cS4","cS5"]
self.sSelector.addItems(screwList)
self.connect(self.sSelector, PythonQt.QtCore.SIGNAL('activated(QString)'), self.sSelector_chosen)
self.__sSelector=''
self.QHBox0 = qt.QHBoxLayout()
self.QHBox0.addWidget(sText)
self.QHBox0.addWidget(self.sSelector)
# self.QHBox0.addWidget(self.okButton)
self.__layout.addRow(self.QHBox0)
# ...
def sSelector_chosen(self, text):
if text != "Select a trajectory":
# cSs...不显示
for node in slicer.util.getNodes("*cS*").values():
mdisp = node.GetDisplayNode()
mdisp.SetSliceIntersectionVisibility(False)
self.__sSelector = text
# logging.debug(self.__sSelector)
self.cScrew = slicer.util.getNode(str(self.__sSelector))
modelDisplay =self.cScrew.GetDisplayNode()
modelDisplay.SetColor(Helper.myColor("red"))
modelDisplay.SetSliceIntersectionVisibility(True)
self.cScrew = slicer.util.getNode("P"+str(self.__sSelector))
modelDisplay =self.cScrew.GetDisplayNode()
modelDisplay.SetColor(Helper.myColor("red"))
modelDisplay.SetSliceIntersectionVisibility(True)
还有缺陷…还好吧回头再改进入下一个节段…