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. Styling QListWidget

Styling QListWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 902 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.
  • Q Offline
    Q Offline
    qt.1234
    wrote on last edited by
    #1

    Hi, I am having issue styling my ListWidget. My ListWidget is created in the UI file in qt creator. Also, I have make use of the stylesheet to customize the appearance of the ListWidget that i have.

    QListView::item
    {
    height: 25px;
    }

    QListView::item::selected
    {
    background-color: rgb(255,128,0);
    min-height: 25px;
    border-radius: 0px;
    }

    On and off, Items will be added to the ListWidget while the program run. However, i notice the margin between items added in the UI and using code is different. How can i correct it?

    Secondly, How can I draw a line to separate the items in a ListWidget?

    Lastly, how do i make the ListWidget scroll able?

    Please advise, Thank you

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

      Hi,

      Please provide a minimal compilable example that shows the behaviour.

      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
      2
      • qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by qwasder85
        #3
        QListView::item::selected
        

        There should be only one colon before the state-specifier "selected".
        Like this:

        QListView::item:selected
        

        To draw a separator between items, you could do something like this:

        QListView::item:!last
        {
            border-bottom: 1px solid black;
        }
        

        This should draw a 1px black border on every item's bottom except for the last item.

        The QListView will display scrollbars when the content becomes larger than the available space. If that's not the case, then you're probably handling its size logic manually somewhere or you have a bug in your layout. ;)

        1 Reply Last reply
        2
        • Q Offline
          Q Offline
          qt.1234
          wrote on last edited by
          #4

          Hi! I have tried using "QListView::item:selected" and it works!! As for the separator, how to i draw it for specific items in the QListWidget? For instance, I have 5 items in my ListWidget (A, B, C, D, E). The position of this 5 items will change now and then. So how to ensure that always after item C i will draw the separator?

          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 Extensions
          • Unsolved