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"
{
this->setObjectName("cbo1");
this->cbo2->setObjectName("cbo2");
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
));
}
layout->addWidget(this->cbo1);
layout->addWidget(this->cbo2);
layout->addWidget(this->cbo3);
setCentralWidget(frame);
}
MainWindow::~MainWindow()
{
}
#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()
{
}
To copy to clipboard, switch view to plain text mode
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:
{
background-color: red;
}
{
background-color: yellow;
/*margin-left: 5px;*/
margin-bottom: 2px;
}
{
background-color: yellow;
margin-top: 0px;
padding-top: 0px;
margin-bottom: 0px;
padding-bottom: 0px;
background-clip: margin;
outline: none;
}
{
background-color: #c0c0c0;
padding-left: 5px;
}
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;
}
To copy to clipboard, switch view to plain text mode
It looks like this:
normal.png(cbo1)margin.png(cbo2)padding.png(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?
Bookmarks