PYQT5:QCHECKBOXES像收音机一样起作用
我有一些复选框,应该在地图上显示不同的区域。当我单击其中一个时,它可以很好地工作,但是当按下多个以上时,它们开始像常规的广播盒一样(即通过新区域代替旧区域;不显示两者)。我确定问题是在drawObjects
中,但我无法弄清楚。有人知道我如何解决吗?
for i in range(len(self.floorMap.classes)):
self.sem_index.insert(i, QCheckBox(self.floorMap.classes[i]))
sem_label_group.addButton(self.sem_index[i])
sem_label_box.addWidget(self.sem_index[i])
self.sem_index[i].stateChanged.connect(self.check_clicked)
def check_clicked(self):
rbtn = self.sender()
text = rbtn.text()
if rbtn.isChecked() == True:
self.semMapID = self.floorMap.classes.index(text)
obj = self.floorMap.rooms[self.currentRoom].objects[self.currentObjInd]
self.drawObjects(self.semMapID, obj.id)
def drawObjects(self, semLabel, objId=-1):
clr = cm.rainbow(np.linspace(0, 1, len(self.floorMap.classes)))
self.drawn_map = self.highlight_map.copy()
noDrawInd = len(self.floorMap.classes) + 1
allDrawInd = len(self.floorMap.classes)
if semLabel != noDrawInd:
for roomID, room in enumerate(self.floorMap.rooms):
for obj in room.objects:
if (obj.semLabel == semLabel) or (semLabel == allDrawInd):
color = 255 * clr[obj.semLabel, :3]
x1, y1, x2, y2 = obj.position
if (objId == obj.id) and (roomID == self.currentRoom):
cv2.rectangle(self.drawn_map, (x1, y1), (x2, y2), color, -1)
else:
cv2.rectangle(self.drawn_map, (x1, y1), (x2, y2), color, 1)
image = QImage(
self.drawn_map,
self.drawn_map.shape[1],
self.drawn_map.shape[0],
self.drawn_map.shape[1] * 3,
QImage.Format_RGB888,
)
self.edit_pix = QPixmap(image)
self.main_image.img = self.edit_pix
self.main_image.setPixmap(self.edit_pix)
编辑:没有LAMDA的更新
I have a few checkboxes that are supposed to display different areas on a map. When I click one of them--it works perfectly well, but when more than one is pressed they begin to act like regular radio boxes (i.e. replacing the old areas by the new areas; not displaying both). I'm sure the issue is in drawObjects
, but I can't figure it out. Does anyone know how I can fix it?
for i in range(len(self.floorMap.classes)):
self.sem_index.insert(i, QCheckBox(self.floorMap.classes[i]))
sem_label_group.addButton(self.sem_index[i])
sem_label_box.addWidget(self.sem_index[i])
self.sem_index[i].stateChanged.connect(self.check_clicked)
def check_clicked(self):
rbtn = self.sender()
text = rbtn.text()
if rbtn.isChecked() == True:
self.semMapID = self.floorMap.classes.index(text)
obj = self.floorMap.rooms[self.currentRoom].objects[self.currentObjInd]
self.drawObjects(self.semMapID, obj.id)
def drawObjects(self, semLabel, objId=-1):
clr = cm.rainbow(np.linspace(0, 1, len(self.floorMap.classes)))
self.drawn_map = self.highlight_map.copy()
noDrawInd = len(self.floorMap.classes) + 1
allDrawInd = len(self.floorMap.classes)
if semLabel != noDrawInd:
for roomID, room in enumerate(self.floorMap.rooms):
for obj in room.objects:
if (obj.semLabel == semLabel) or (semLabel == allDrawInd):
color = 255 * clr[obj.semLabel, :3]
x1, y1, x2, y2 = obj.position
if (objId == obj.id) and (roomID == self.currentRoom):
cv2.rectangle(self.drawn_map, (x1, y1), (x2, y2), color, -1)
else:
cv2.rectangle(self.drawn_map, (x1, y1), (x2, y2), color, 1)
image = QImage(
self.drawn_map,
self.drawn_map.shape[1],
self.drawn_map.shape[0],
self.drawn_map.shape[1] * 3,
QImage.Format_RGB888,
)
self.edit_pix = QPixmap(image)
self.main_image.img = self.edit_pix
self.main_image.setPixmap(self.edit_pix)
Edit: Updated without the lamda
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论