mentalmushroom
6th March 2013, 07: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?
#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?