Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QListview margin transparent



  • Hi,

    I am setting the stylesheet of a QListView by
    listView->setStylesheet(QListView {
    color:blue;
    background:red;
    border-top:1px solid gray;
    margin:2px;})

    WHen I set a margin, I see a 2px with around the list which is white in color. SOmehow I cannot control the color of this margin around the listview. How can I control that? I want to make the margin transparent.


  • Lifetime Qt Champion

    Hi,

    Can you show a complete QListView initialization so that other can try to reproduce your use case with the same code ?



  •     QListView *listView = new QListView(this);
        listView->setStyleSheet("QListView {\
                                    color: rgb(72,72,72);\
                                    background-color: rgb(228,228,228);\
                                    border-top: 0px solid rgb(40,40,40); min-width:133px;\
                                    margin:0px;\
                                 }\
                                 QListView::item:hover {\
                                    color:rgb(228,228,228);\
                                    background-color: rgb(72,72,72);\
                                 }\
                                 ");
         setView(listView);
    
    

  • Lifetime Qt Champion

    On what are you setting that view ?



  • @SGaist I apologise for the delayed response. I am setting this on a combobox. It works correctly. The only problem is that the popup keeps jumping every time I click on the combobox.


  • Lifetime Qt Champion

    Can you add your combo box initialization to the code ? That way it can be tested the same as you have on your machine.

    By the way, which OS/Qt version are you running ?



  • @SGaist Sorry for the delay. I am working on Mac. Qt 5.5. My problem has changed a little.
    This is my complete code. Everything works correctly. Except that the popup of the comboBox keeps jumping every time I click on the drop down.

    IvySnapshotComboBox::IvySnapshotComboBox(QWidget *parent):
        QComboBox(parent)
    {
    
        //Do not insert item to combobox on pressing enter
        setInsertPolicy(QComboBox::NoInsert);
        //Set its size policy to [fixed,fixed]
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        //Set height and width
        setFixedSize(133,36);
     
        QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
        setItemDelegate(itemDelegate);
    
        setStyleSheet("QComboBox {\
                      border: 0px solid rgb(228,228,228);\
                          border-radius: 3px;\
                      font-family: \"Helvetica Neue Med\";\
                      font-size: 11px;padding-left:31px;margin-top:1px;\
                  }\
                  \
                  QComboBox:!editable {\
                      color: rgb(72,72,72);\
                      background:  rgb(228,228,228);\
                  }\
                  \
                  QComboBox::drop-down {\
                      background:  rgb(228,228,228);border-radius: 3px;\
                      width: 40px;\
                  }\
                  \
                  QComboBox::down-arrow {\
                      subcontrol-position: left;\
                      image: url(:/images/Arrow_on.png);\
                  }\
                  QComboBox::down-arrow:on { \
                      image: url(:/images/Arrow_on.png);\
                  }QComboBox QListView{ color:red; background:yellow;margin:5px;}\
                  ");
          QListView *listView = new QListView(this);
          listView->setStyleSheet("QListView {\
                                      color: rgb(72,72,72);margin:0px;border-radius:3px;\
                                      selection-background-color: rgb(72,72,72);\
                                        border: 0px solid rgb(228,228,228);\
                                      background: rgb(228,228,228);min-width:133px;\
                                   }\
                                    QListView::item:selected{ min-height:50px;}\
                                   QListView::item:hover {\
                                        color: rgb(228,228,228);\
                                      background-color: rgb(72,72,72);\
                                   }\
                                ");
        setView(listView);
        QStringList list;
        list << "Shirt" << "Shoe";
        addItems(list);
    }
    void IvySnapshotComboBox::showPopup()
    {
        QComboBox::showPopup();
        QWidget *popup = this->findChild<QFrame*>();
        popup->move(popup->x()+8,popup->y()-(maxElements-i)*this->height()-2);
    }
    

  • Lifetime Qt Champion

    Jumping ? Likely because you are moving it by hand. Why are you moving it by hand ?



  • @SGaist Moving it by hand? Do you mean the show Popup function(). Even if I don't use that, the position is inconsistent with this code.


  • Lifetime Qt Champion

    Can you check with a more recent version of Qt ?

    I can't reproduce your problem, I don't know what i should be. But if I remove the showPopup method it shows the combobox at the right place for OS X.