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. QListview margin transparent
Forum Updated to NodeBB v4.3 + New Features

QListview margin transparent

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistviewmarginstylesheet
10 Posts 2 Posters 5.5k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by
    #1

    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.

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

      Hi,

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

      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
      • S Offline
        S Offline
        sunil.nair
        wrote on last edited by
        #3
            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);
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          On what are you setting that view ?

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

          S 1 Reply Last reply
          1
          • SGaistS SGaist

            On what are you setting that view ?

            S Offline
            S Offline
            sunil.nair
            wrote on last edited by sunil.nair
            #5

            @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.

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

              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 ?

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

              S 1 Reply Last reply
              1
              • SGaistS SGaist

                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 ?

                S Offline
                S Offline
                sunil.nair
                wrote on last edited by
                #7

                @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);
                }
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

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

                  S 1 Reply Last reply
                  0
                  • SGaistS SGaist

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

                    S Offline
                    S Offline
                    sunil.nair
                    wrote on last edited by
                    #9

                    @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.

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

                      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.

                      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
                      0

                      • Login

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