Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLabel省略模式和超链接显示问题 #99

Open
biubiubiu533 opened this issue Aug 1, 2024 · 0 comments
Open

MLabel省略模式和超链接显示问题 #99

biubiubiu533 opened this issue Aug 1, 2024 · 0 comments

Comments

@biubiubiu533
Copy link
Contributor

biubiubiu533 commented Aug 1, 2024

  1. MLabel在设置省略模式时,resize的时候文本只会缩短不会扩展,感觉是因为每次resize都沿用了之前缩短后的文本,没有使用原始的完整文本
  2. MLabel在显示超链接文本时,如果使用了省略模式,超链接文本也被省略了从而不能正常显示
20240729101900_rec_.mp4

可能的修改方式
把MLabel中的text和setText方法改为使用”dayu_text“,”dayu_text“保存完整文本,”text“保存显示文本

    def text(self):
        """
        Overridden base method to return the original unmodified text

        :returns:   The original unmodified text
        """
        return self.property("dayu_text")

    def setText(self, text):
        """
        Overridden base method to set the text on the label

        :param text:    The text to set on the label
        """
        self.setProperty("dayu_text", text)
        self._update_elided_text()
        self.setToolTip(text)

在_update_elided_text方法中区分是否为html形式,若是则不使用省略模式

    def _update_elided_text(self):
        """
        Update the elided text on the label
        """
        _font_metrics = self.fontMetrics()
        text = self.property("dayu_text")
        text = text if text else ""
        # 检查文本是否包含 HTML 标签
        is_html = bool(re.search(r'<[^>]+>', text))

        if is_html:
            # 如果文本包含 HTML 标签,直接设置富文本
            super(MLabel, self).setText(text)
        else:
            # 否则,使用省略模式设置文本
            _elided_text = _font_metrics.elidedText(text, self._elide_mode, self.width() - 2 * 2)
            super(MLabel, self).setText(_elided_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant