坑记-- QComboBox() By Python

从这组代码开始

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)

在这里插入图片描述

还有缺陷…还好吧回头再改进入下一个节段…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jumbo Jing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值