Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSS for QTabBar close button: visible on selected OR hovered
QtWS25 Last Chance

QSS for QTabBar close button: visible on selected OR hovered

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 43 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrzejB
    wrote last edited by
    #1

    I am trying to customize the close button visibility on a QTabBar (used within QTabWidget with setTabsClosable(true)). My specific goal for the close button (QTabBar::close-button) is to make it visible only when:
    The parent tab (QTabBar::tab) is currently selected (:selected). OR
    The parent tab is not selected (:!selected), BUT the mouse cursor is currently hovering over that specific non-selected tab (:hover).
    (this is style similar I saw in JetBrains IDEs)

    In all other cases (i.e., a non-selected tab that is not being hovered), the close button should be hidden.

    I understand this requires styling the ::close-button subcontrol based on the state of the parent ::tab element. I've found that applying simple rules like image: none conditionally using selectors like QTabBar::tab:!selected QTabBar::close-button doesn't always seem reliable, potentially due to interactions with the underlying QStyle.

    Could someone suggest the best or most reliable QSS approach to achieve this specific logic?

    What QSS selectors and properties should I use to correctly show the close button on selected tabs and on non-selected tabs when they are hovered, while hiding it otherwise?
    Crucially, is the proposed QSS solution likely to work consistently across both Qt 5 and common Qt 6 versions? Are there any known QSS interpretation differences or QStyle limitations between Qt5 and Qt6 that might affect this particular scenario?

    Any QSS examples or advice would be greatly appreciated!

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      I think that for this case, you should consider creating a QProxyStyle in order to be able to manage that hierarchy of constraints.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved