PDA

View Full Version : QComboBox popup arrows [Mac OS X]



mentalmushroom
6th March 2013, 08:10
I have noticed some strange behavior when applied the stylesheet to QComboBox on Mac OS X: changing properties like margin or padding produces arrows for the popup. Here is the code:



#include <QVBoxLayout>
#include <QLineEdit>
#include "mainwindow.h"

MainWindow::MainWindow(): QMainWindow()
{
QFrame *frame = new QFrame;

this->cbo1 = new QComboBox;
this->setObjectName("cbo1");

this->cbo2 = new QComboBox;
this->cbo2->setObjectName("cbo2");

this->cbo3 = new QComboBox;
this->cbo3->setObjectName("cbo3");

for (int i = 0; i < 10; ++i)
{
this->cbo1->addItem("item " + QString::number(i));
this->cbo2->addItem("item " + QString::number(i));
this->cbo3->addItem("item " + QString::number(i));
}

QVBoxLayout *layout = new QVBoxLayout(frame);
layout->addWidget(this->cbo1);
layout->addWidget(this->cbo2);
layout->addWidget(this->cbo3);

setCentralWidget(frame);
}

MainWindow::~MainWindow()
{
}


There are three comboboxes: cbo1, cbo2, cbo3. For cbo1 I didn't change neither margin nor padding, for cbo2 I changed margin-bottom and for cbo3 I changed padding-left. The stylesheet is shown below:


QComboBox QAbstractItemView
{
background-color: red;
}

QComboBox#cbo2
{
background-color: yellow;
/*margin-left: 5px;*/
margin-bottom: 2px;
}

QComboBox#cbo2 QAbstractItemView
{
background-color: yellow;
margin-top: 0px;
padding-top: 0px;
margin-bottom: 0px;
padding-bottom: 0px;
background-clip: margin;
outline: none;
}

QComboBox#cbo3
{
background-color: #c0c0c0;
padding-left: 5px;
}


It looks like this:
8790(cbo1)8789(cbo2)8791(cbo3)

As you can see, cbo2 and cbo3 have some strange arrows in their popup. Is it possible to prevent this or change appearance of those arrows so they better fit to the control style?

m3rlin
13th March 2013, 10:38
This is a Mac OS issue. I read about a work around somewhere. I recall manipulating the position of the arrow so it goes off screen, and or not setting the current item... I have no mac Os so I can't test it for you.