PYQT5:QCHECKBOXES像收音机一样起作用

发布于 2025-02-07 22:32:24 字数 1885 浏览 0 评论 0原文

我有一些复选框,应该在地图上显示不同的区域。当我单击其中一个时,它可以很好地工作,但是当按下多个以上时,它们开始像常规的广播盒一样(即通过新区域代替旧区域;不显示两者)。我确定问题是在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文