Hi all,
I would like to set with stylesheet the item's height when combo's pop up opens.
any suggestion?
thank you
Beppe
Printable View
Hi all,
I would like to set with stylesheet the item's height when combo's pop up opens.
any suggestion?
thank you
Beppe
It seems not possible with style sheet...
I tried -
but it doesnt work
try to set an item size throught a model
Code:
#include <QtGui> #include <QApplication> int main(int argc, char **argv) { QComboBox cb; cb.show(); return app.exec(); }
Thank you spirit, it works.
I have another problem. I would like to change the scrollbar of the items' list. I have to use the function
and set my scrollbar for QAbstractItemView using
???
Am i rught ?
you can get a view using QComboBox::view and then set a new scroll bar.
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
Code:
#include "mycombobox.h" { 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;\ }\ "); }
mycombobox.h
Code:
#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
and my scrollbar code is
myscrollbar.cpp
Code:
{ 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);\ }\ "); } { } { }
myscrollbar.h
Code:
#ifndef MYSCROLLBAR_H #define MYSCROLLBAR_H #include <QtCore> #include <QtGui> #include <QScrollBar> { Q_OBJECT Q_DISABLE_COPY(myscrollbar) public: }; #endif // MYSCROLLBAR_H
have you any idea of the problem ?
why do you create own scroll bar? you just can set a style sheet for already created scrollbar in a combobox, e.g.
orCode:
... cb->view()->setStyleSheet(...); ...
or I missed something?Code:
... cb->view()->verticalScrollBar()->setStyleSheet(...); ...
I'm not expert, so you may be right.
Actually I want to use my scrollbar for other widget such as ScrollArea and I think my code is more flexible if I define my custom scrollbar.
if you wanna apply your style sheet for all scrollbars in your app then use QApplication::setStyleSheet.
Thank you for the suggestion