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. [SOLVED] QComboBox Items spacing

[SOLVED] QComboBox Items spacing

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 6.6k 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.
  • B Offline
    B Offline
    bareil76
    wrote on 19 Aug 2013, 19:38 last edited by
    #1

    Hi,

    I have a problem with a QComboBox. The list is 9 items long and some of them are 2 lines long.

    So it gets difficult to read the list. I would like to add some more space between the items.

    I tried using stylesheets, but it did not work. Do you have any ideas on how to do this?

    Thanks

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pkj__
      wrote on 20 Aug 2013, 08:38 last edited by
      #2

      QComboBox::view() will give a QAbstractItemView pointer. Since the view is a list view, you can cast it safely to QListView. Use QListView::setSpacing() to something of your choice. Default value is 0.
      @
      QAbstractItemView *abVw = comboInst->view();
      QListView listVw = qobject_cast<QListView>(abVw);
      if (listVw) {
      listVw->setSpacing(2);
      }
      @

      1 Reply Last reply
      1
      • B Offline
        B Offline
        bareil76
        wrote on 20 Aug 2013, 11:57 last edited by
        #3

        THANK YOU!

        Just What I needed!

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bareil76
          wrote on 21 Aug 2013, 13:13 last edited by
          #4

          Here is a bonus for anyone having the same question as i did.

          here is what I did

          @QAbstractItemView *abVw = SetMode->view();
          QListView listVw = qobject_cast<QListView>(abVw);
          if (listVw) {
          listVw->setSpacing(2);
          listVw->setAlternatingRowColors(1);
          QPalette p= listVw->palette();
          p.setColor(QPalette::AlternateBase, Qt::lightGray);
          listVw->setPalette(p);
          }@

          where SetMode is a pointer to my ComboBox. It sets an alternating color for the comboBox at the same time giving it some nice spacing

          1 Reply Last reply
          0

          3/4

          20 Aug 2013, 11:57

          • Login

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