Qt-interest Archive, March 2008
combobox style help
Message 1 in thread
------------------------------------------------------------------------
I have no hope in getting any answer since too many questions in this
forum are unsolved/unanswered but this is my last chance to get a solution.
I'm doing my own style. And i've done almost all built-in widgets
graphs. But like many people i'm stuck in QComboBox. I've managed to
remake all it's graphs following qt's sources (4.3.3) like you can see
in attatched pngs, but i'm still stuck on the delegate popup, since i've
get lost in the styles sources(and also with "assistant") when i try to
locate it's paint structure.
I don't want any code snipet, i only ask for a clear qcombobox popup
drawing structure(or maybe steps) and/or PE_ SH_... and all this stuff
enums that get involved in a standard combo popup drawing.
Now i'm fighting with StyleHints SH_... (see png's) and i'm working
arround qframe::NoFrame...::Box::FlatPanel...etc... and all it's
behaviours... i think i'm so close to get the correct way... but in
fact, i'm only getting more gray hair than other real approachZunge raus
I've seen so far all qt4 examples and how-tos, so please, don't answer
this thread with it.
Please, there's anybody out there that know the correct answer?
Signature:
"i've seen sources you people couldn't believe"
I hope this thread won't get lost "like tears in rain" and my project
won't look like "it's time to die"... (yes... a freak end )
--
[ signature omitted ]
Message 2 in thread
Off List...
Creating a custom style and be a painful thankless job...
And frankly, I don't think many have done it...Except for the QT guys
themselves.
First... you didn't attach any PNGs, but Im really not sure what they
would of shown anyway..
I have done a complete style (derived from windows style), and just
about every widget was custom drawn...
For a combobox, you will need (I may miss 1 or 2, as its very easy to
miss)
In method, drawPrimitive, you will need to handle primitive element,
PE_Frame
In method, drawComplexControl, handle ComplexControl
CC_COmboBox <== here is where it starts, follow it for all sorts of
paths to find whats necessary )
In method, subControlRect, handle ComplexControl CC_ComboBox, and for
all the SubControls
SC_COmboBoxArrow, SC_CombBoxEditField
In method sizeFromContents for ContentsType CT_ComboBox
Depending on what changes your making, you may need to tweak
standardPixmap, styleHint, and pixelMetric as well
If you need further help, let me know... I do QT consulting for a
living, and Im sure I can help you out... If you know what you want for
a custom style, I can put together a bid for it pretty quickly.
Scott
> -----Original Message-----
> From: Jaume Rodriguez [mailto:jrodriguez@xxxxxxxxxxxxxx]
> Sent: Friday, March 07, 2008 4:18 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: combobox style help
>
>
-----------------------------------------------------------------------
> -
> I have no hope in getting any answer since too many questions in this
> forum are unsolved/unanswered but this is my last chance to get a
> solution.
>
> I'm doing my own style. And i've done almost all built-in widgets
> graphs. But like many people i'm stuck in QComboBox. I've managed to
> remake all it's graphs following qt's sources (4.3.3) like you can see
> in attatched pngs, but i'm still stuck on the delegate popup, since
> i've
> get lost in the styles sources(and also with "assistant") when i try
to
> locate it's paint structure.
> I don't want any code snipet, i only ask for a clear qcombobox popup
> drawing structure(or maybe steps) and/or PE_ SH_... and all this stuff
> enums that get involved in a standard combo popup drawing.
>
> Now i'm fighting with StyleHints SH_... (see png's) and i'm working
> arround qframe::NoFrame...::Box::FlatPanel...etc... and all it's
> behaviours... i think i'm so close to get the correct way... but in
> fact, i'm only getting more gray hair than other real approachZunge
> raus
>
> I've seen so far all qt4 examples and how-tos, so please, don't answer
> this thread with it.
> Please, there's anybody out there that know the correct answer?
>
>
> Signature:
> "i've seen sources you people couldn't believe"
> I hope this thread won't get lost "like tears in rain" and my project
> won't look like "it's time to die"... (yes... a freak end )
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 3 in thread
****I posted this mail also on Qtforums****
well i think my research is over. i'll try to explain.
Since i've achieved my QComboBox label-button style through
MyCustomStyle, i needed to restyle its popup-dropdown menu. And it
wasn't trivial.
my approach is that:
Qt uses QAbstractItemView/QAbstractItemDelegate classes for model/views
purposes.
Those classes are used in some widgets.
Those have a few kind of objects that are involved on data structure and
its view.
As we can see on Qt's Assistant section "An Introduction to Model/View
Programming" we need a kind of object called "delegate".
This delegates manage default combo's popup.
It seems that QComboBox draws only label-drop_down button (see attatched
PNG) and let popup drawing to it's delegate. This delegate (don't mind
which is) inherits QItemDelegate that is a child class of
QAbstractItemDelegate.
So, how to access QComboBox delegate?
Maybe we can subclass QComboBox...
this is an approach suggested on Qt's example "Spin Box Delegate".
This is, doing a custom delegate, that inherits QItemDelegate doing:
-class MyDelegate : public QItemDelegate
and implementing on it:
+paint(QPainter *painter, const QStyleOptionViewItem &option, const
QModelIndex &index) const
+drawBackground(painter, opt, index);
+drawCheck(painter, opt, checkRect, checkState);
+drawDecoration(painter, opt, decorationRect, pixmap);
+drawDisplay(painter, opt, displayRect, text);
+drawFocus(painter, opt, displayRect);
and then creating a CustomComboBox that includes mydelegate.h and in its
constructor writting:
+MyDelegate delegate;
+setItemDelegate(delegate); //maybe with this.setItemDelegate...if you want
This sentences tells to your combo that our new-brand delegate must
override combo's default popup delegate.
It's all. How we modify it's a design issue
I strongly suggest finding paint() and draw*(); -(*) as wildcard not as
pointer :p- in Qt QItemDelegate sources to see how they work and also
following its recomendations that must be token in account to maintain a
correct behaviour. Hint->methods comments before each implementation
Zunge raus
But, this is only for QComboBox... feel free to play with other widgets
based on delegates. Moreover, you can define more abstract and general
delegates that not only affects combos...
Also a good reference on delegate creation is Qt's example-and
assistant-(are slighty different) "Spin Box Delegate".
I'll will put some PNG as soon as i achieve my wanted styled popup. And
if wanted, some snipets. But as i said in my first post, i wanted to
know how combos structure was done. Because of that, i've posted an
abstract on how Qt's seems to work in those cases.
Maybe it's not a smart and clever approach but due to lack of info about
relations between styles and views, i had to do my way through Qt's
source code and documentation... so any suggestions are wellcome if
there's any more clever solution. Also i want to notice that i miss a
good document in Qt 4 distro that could eventually describe a general Qt
structure in terms of modules and classes relations and how they work to
achieve complex behaviours of this library that involves none homogenic
tematic modules. I meant, Qt is well documented, but i feel that
Assistant explanation is unconexed. So... i feel happy to digg and find
my way through sources(it's encouraging to me) but i think this is
making a laegion of standard Qt coder so limited to Books and tutorials
that approach Qt if it were M$-VB... there's so many explanantion on
designer for example and other hard and complex library info are left to
more psycho-digger coders like me :P and we are less than
standard-hobbist Qt coder...is that good for Qt's community?
Thanks to all!!
Jaume RB
--
[ signature omitted ]