隐藏Qt标签的标签文本,而不将文本设置为空字符串 [英] Hide label text for Qt tabs without setting text to empty string

查看:290
本文介绍了隐藏Qt标签的标签文本,而不将文本设置为空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个带有图标的 QTabWidget



如何隐藏标签的标签文本Qt?我不能将文本设置为空字符串(),因为我使用停靠的小部件( QDockWidget



但是在标签模式下,我只想显示标签的图标(如果小部件是浮动的,我需要它)。
可能的方法:


  1. 字体大小为0?

  2. 自己的栏类,并将



    也许我将自己创建整个标签栏,因为自动生成的东西太难处理(同意PS)。

    解决方案

    如果你不想看到文本,可以将其设置为空



    我认为API中没有任何内容不是那么常见的情况,这意味着你需要自己做。



    现在,你可以声称,对许多小部件来说,这是乏味的,但另一方面,你可以写一个简单的哈希定义或内联函数为你做这个重复的工作,这只会导致一个线程调用,基本上,你需要使用反正改变状态。


    I need a QTabWidget with icons only:

    How can I hide the label text of a tab in Qt? I cannot set the text to an empty string (""), as I am using docked widgets ( QDockWidget ) and the label text is set automatically (and I need it if the widget is floating).

    But in tabbed mode I just want to display the icons (of the tabs). Possible approaches:

    1. Font size to 0?
    2. I need to create my own bar class and override the paint event as here

    Anything easier / cleaner?

    --- Edit ---

    Ok, the "set window title to empty string, and reset it the original text" approach works. I am using the topLevelChanged signal for this. However, it has some drawbacks, as the empty text still occupies some space. Another issue, with the text the tooltip is gone, and I cannot set it back.

    What I am currently trying is something in-between the "text empty" and Prasad Silva's approach. I try to identify the text label inside the tab and set its size to 0, then reset it. It's slightly different, but would keep the text intact.

    Btw, I see a line on top of my tabs, any idea what this is (where it comes from)? Edit: There seems to be no "easy way" (style sheet, attribute) for this, see Hiding bottom line in QTabBar

    Maybe I will create the whole tab bar on my own, as the automatically generated stuff is just too hard to handle (agree with PS on this).

    解决方案

    If you do not want to see the text, you can set it to an empty text after saving the current text, and when you want to see it again, restore it from the stored variable.

    I do not think there is anything in the API for this not so common case, which means you will need to do it yourself.

    Now, you could claim that it is tedious to do for many widgets, but on the other hand, you could write a simple hash define or inline function to do this repetitive work for you, which would only result a one-liner call, basically, which you would need to use anyway when changing the state.

    这篇关于隐藏Qt标签的标签文本,而不将文本设置为空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆