Thanks again spirit, it works, but my scrollbar is not correctly displayed in the combobox's pop up (see scrollbarComboBox.JPG). When I add my scrollbar to a scrollarea it is correctly displayed (see scrollbarScrollArea.JPG).
my combo box code is
mycombobox.cpp
#include "mycombobox.h"
myComboBox
::myComboBox(QWidget * parent
){
comboScrollBar = new myscrollbar(0);
this->view()->setVerticalScrollBar(comboScrollBar);
this->setStyleSheet(" \
QComboBox { border: 1px solid gray;\
border-radius: 3px;\
padding: 1px 18px 1px 3px; \
min-width: 6em; \
} \
\
QComboBox:editable {\
background: white;\
}\
\
QComboBox:!editable, QComboBox::drop-down:editable {\
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,\
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);\
}\
\
\
QComboBox:!editable:on, QComboBox::drop-down:editable:on {\
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #D3D3D3, stop: 0.4 #D8D8D8,\
stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1);\
}\
QComboBox:on {\
padding-top: 3px;\
padding-left: 4px;\
}\
QComboBox::drop-down {\
subcontrol-origin: padding;\
subcontrol-position: top right;\
width: 54px;\
border-left-width: 1px;\
border-left-color: darkgray;\
border-left-style: solid; \
border-top-right-radius: 3px; \
border-bottom-right-radius: 3px;\
}\
QComboBox::down-arrow {\
image: url(b_droplist.png);\
}\
\
QComboBox::down-arrow:on { \
top: 1px;\
left: 1px;\
}\
QComboBox QAbstractItemView {\
border: 2px solid darkgray;\
selection-background-color: lightgray;\
}\
");
}
#include "mycombobox.h"
myComboBox::myComboBox(QWidget * parent)
: QComboBox(parent)
{
comboScrollBar = new myscrollbar(0);
this->view()->setVerticalScrollBar(comboScrollBar);
this->setStyleSheet(" \
QComboBox { border: 1px solid gray;\
border-radius: 3px;\
padding: 1px 18px 1px 3px; \
min-width: 6em; \
} \
\
QComboBox:editable {\
background: white;\
}\
\
QComboBox:!editable, QComboBox::drop-down:editable {\
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,\
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);\
}\
\
\
QComboBox:!editable:on, QComboBox::drop-down:editable:on {\
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #D3D3D3, stop: 0.4 #D8D8D8,\
stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1);\
}\
QComboBox:on {\
padding-top: 3px;\
padding-left: 4px;\
}\
QComboBox::drop-down {\
subcontrol-origin: padding;\
subcontrol-position: top right;\
width: 54px;\
border-left-width: 1px;\
border-left-color: darkgray;\
border-left-style: solid; \
border-top-right-radius: 3px; \
border-bottom-right-radius: 3px;\
}\
QComboBox::down-arrow {\
image: url(b_droplist.png);\
}\
\
QComboBox::down-arrow:on { \
top: 1px;\
left: 1px;\
}\
QComboBox QAbstractItemView {\
border: 2px solid darkgray;\
selection-background-color: lightgray;\
}\
");
}
To copy to clipboard, switch view to plain text mode
mycombobox.h
#ifndef MYCOMBOBOX_H
#define MYCOMBOBOX_H
#include <QtCore>
#include <QtGui>
#include <QComboBox>
#include "myscrollbar.h"
{
Q_OBJECT
Q_DISABLE_COPY(myComboBox)
public:
private:
myscrollbar *comboScrollBar;
};
#endif // MYCOMBOBOX_H
#ifndef MYCOMBOBOX_H
#define MYCOMBOBOX_H
#include <QtCore>
#include <QtGui>
#include <QComboBox>
#include "myscrollbar.h"
class myComboBox : public QComboBox
{
Q_OBJECT
Q_DISABLE_COPY(myComboBox)
public:
myComboBox(QWidget * parent = 0);
private:
myscrollbar *comboScrollBar;
};
#endif // MYCOMBOBOX_H
To copy to clipboard, switch view to plain text mode
and my scrollbar code is
myscrollbar.cpp
myscrollbar
::myscrollbar(QWidget * parent
){
this->setStyleSheet(" \
QScrollBar::vertical {\
background:lightgray;\
border-color:black;\
border-style:solid;\
width: 15px;\
margin-top:1px;\
margin-bottom:1px;\
}\
\
QScrollBar::add-page:vertical, \
QScrollBar::sub-page:vertical {\
background: none;\
}\
\
QScrollBar::add-line:vertical{\
background:none;\
} \
\
QScrollBar::sub-line:vertical { \
background:none;\
} \
\
QScrollBar::handle:vertical {\
background: url(slider.png);\
\
border-color:black;\
border-style:solid;\
border-width:1px;\
} \
\
QScrollBar::add-line:pressed,\
QScrollBar::sub-line:pressed,\
QScrollBar::handle:pressed{\
background:lightgray;\
background: url(slider.png);\
}\
");
}
QSize myscrollbar
::sizeHint() const {
}
QSize myscrollbar
::minimumSizeHint() const {
}
myscrollbar::myscrollbar(QWidget * parent)
: QScrollBar(Qt::Vertical, parent)
{
this->setStyleSheet(" \
QScrollBar::vertical {\
background:lightgray;\
border-color:black;\
border-style:solid;\
width: 15px;\
margin-top:1px;\
margin-bottom:1px;\
}\
\
QScrollBar::add-page:vertical, \
QScrollBar::sub-page:vertical {\
background: none;\
}\
\
QScrollBar::add-line:vertical{\
background:none;\
} \
\
QScrollBar::sub-line:vertical { \
background:none;\
} \
\
QScrollBar::handle:vertical {\
background: url(slider.png);\
\
border-color:black;\
border-style:solid;\
border-width:1px;\
} \
\
QScrollBar::add-line:pressed,\
QScrollBar::sub-line:pressed,\
QScrollBar::handle:pressed{\
background:lightgray;\
background: url(slider.png);\
}\
");
}
QSize myscrollbar::sizeHint() const
{
return QSize(50,96);
}
QSize myscrollbar::minimumSizeHint() const
{
return QSize(50,96);
}
To copy to clipboard, switch view to plain text mode
myscrollbar.h
#ifndef MYSCROLLBAR_H
#define MYSCROLLBAR_H
#include <QtCore>
#include <QtGui>
#include <QScrollBar>
{
Q_OBJECT
Q_DISABLE_COPY(myscrollbar)
public:
QSize minimumSizeHint
() const;
};
#endif // MYSCROLLBAR_H
#ifndef MYSCROLLBAR_H
#define MYSCROLLBAR_H
#include <QtCore>
#include <QtGui>
#include <QScrollBar>
class myscrollbar : public QScrollBar
{
Q_OBJECT
Q_DISABLE_COPY(myscrollbar)
public:
myscrollbar(QWidget * parent = 0);
QSize sizeHint() const;
QSize minimumSizeHint() const;
};
#endif // MYSCROLLBAR_H
To copy to clipboard, switch view to plain text mode
have you any idea of the problem ?
Bookmarks