Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTabBar-like list of "x-clickable" buttons?
Qt 6.11 is out! See what's new in the release blog

QTabBar-like list of "x-clickable" buttons?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 533 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.
  • NathanielN Offline
    NathanielN Offline
    Nathaniel
    wrote last edited by Nathaniel
    #1

    There's a common pattern in web UIs where they show a list of items via "buttons" (more precisely, "labels" in the Qt sense because the widget as a whole is not clickable) with a small, clickable "x" in the top-left corner. Clicking on the "x" removes the label from the list. The label is usually in a flat-button style with a thin border. In Qt, one might add labels to the list by choosing from a QComboBox.

    As far as I know, Qt has no native buttons/labels with this kind of functionality. However, it is similar to how QTabBar works with tabsClosable set to true. So maybe a list of such buttons could be implemented via an ordinary QTabBar and changing the styling. However, this is obviously an atypical use of QTabBar and it might take a lot of work to get the style right so it doesn't confuse the user; there's no QStackWidget being controlled by the tab bar.

    Is there a 3rd party library that might have such as QLabel subclass implemented already?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      IgKh
      wrote last edited by IgKh
      #2

      The common name for the kind of component you describe is a "Tags Input". Just so you can more easily search for it. A quick search finds some previous efforts to build one for Qt Widgets.

      If I had to do something like this myself, the initial approach I would have taken is to subclass QLineEdit and override the paintEvent to draw the tag pills in a margin (the margins are customizable). A rectangle with an X and a little bit of text is relatively easy to draw yourself with the QPainter API, there is no need to reach for QLabel. Detecting clicks can be done in an override of mouse down events. You can go fancy with making the backspace key work deleting tags when at the beginning of the line edit area, and what not.

      JonBJ 1 Reply Last reply
      0
      • I IgKh

        The common name for the kind of component you describe is a "Tags Input". Just so you can more easily search for it. A quick search finds some previous efforts to build one for Qt Widgets.

        If I had to do something like this myself, the initial approach I would have taken is to subclass QLineEdit and override the paintEvent to draw the tag pills in a margin (the margins are customizable). A rectangle with an X and a little bit of text is relatively easy to draw yourself with the QPainter API, there is no need to reach for QLabel. Detecting clicks can be done in an override of mouse down events. You can go fancy with making the backspace key work deleting tags when at the beginning of the line edit area, and what not.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote last edited by
        #3

        @IgKh
        I know nothing about this. Ooi why do you want a QLineEdit, which is ostensibly for text input, rather than a QLabel?

        I 1 Reply Last reply
        0
        • JonBJ JonB

          @IgKh
          I know nothing about this. Ooi why do you want a QLineEdit, which is ostensibly for text input, rather than a QLabel?

          I Offline
          I Offline
          IgKh
          wrote last edited by
          #4

          @JonB A text edit (often with a completer and/or a combo box style drop down menu) is a typical part of such a component, as the UX for adding a tag is to type it and hit return. You can see a live example like https://www.chakra-ui.com/docs/components/tags-input.

          JonBJ 1 Reply Last reply
          0
          • I IgKh

            @JonB A text edit (often with a completer and/or a combo box style drop down menu) is a typical part of such a component, as the UX for adding a tag is to type it and hit return. You can see a live example like https://www.chakra-ui.com/docs/components/tags-input.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote last edited by JonB
            #5

            @IgKh said in QTabBar-like list of "x-clickable" buttons?:

            adding a tag is to type it and hit return

            Fair enough. I think different from what I took from the OP's description. At least I understand.

            (I get it now. Your "Tags Input" is those adding a bunch of tags to a topic by typing in words on little "cards", and "x" to delete one.)

            1 Reply Last reply
            0

            • Login

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