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
QtWS25 Last Chance

QListview margin transparent

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistviewmarginstylesheet
10 Posts 2 Posters 5.3k 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.
  • S Offline
    S Offline
    sunil.nair
    wrote on 22 Sept 2016, 18:27 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Sept 2016, 22:08 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 23 Sept 2016, 05:49 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Sept 2016, 20:21 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 26 Sept 2016, 03:18
          1
          • S SGaist
            23 Sept 2016, 20:21

            On what are you setting that view ?

            S Offline
            S Offline
            sunil.nair
            wrote on 26 Sept 2016, 03:18 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 26 Sept 2016, 07:10 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 28 Sept 2016, 19:26
              1
              • S SGaist
                26 Sept 2016, 07:10

                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 28 Sept 2016, 19:26 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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 28 Sept 2016, 19:46 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 29 Sept 2016, 02:28
                  0
                  • S SGaist
                    28 Sept 2016, 19:46

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

                    S Offline
                    S Offline
                    sunil.nair
                    wrote on 29 Sept 2016, 02:28 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
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 1 Oct 2016, 21:18 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

                      7/10

                      28 Sept 2016, 19:26

                      • Login

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