Qt4. Why no sizePolicy virtual method in QLayoutItem?
-
I want to implement own QLayoutItem successor, but I can't provide QSizePolicy to layout, because no sizePolicy virtual method in QLayoutItem.
I looked into Qt sources and found that QLayout takes sizePolicy directly from QWidget avoiding QWidgetItem.
Why trolls have done so? And what I can do?
-
-
[quote author="navrocky" date="1284623322"]I want to implement own QLayoutItem successor, but I can't provide QSizePolicy to layout, because no sizePolicy virtual method in QLayoutItem.
I looked into Qt sources and found that QLayout takes sizePolicy directly from QWidget avoiding QWidgetItem.
[/quote][quote author="navrocky" date="1284626855"]i can't provide sizePolicy to a layout, because no virtual sizePolicy in QLayouItem. I can't provide stretch factors too in my subclass. [/quote]
But looking at the docs for QWidget,
QSizePolicy
This property holds the default layout behavior of the widget.
If there is a QLayout that manages this widget's children, the size policy specified by that layout is used. If there is no such QLayout, the result of this function is used.So why not pick the right layout and let it handle the QWidget/QLayoutItem sizes? I've done some complicated UIs by just using what's available. Can you post some code and explain what you are trying to do, maybe someone can help...
-
Ok, I explain what I want to do.
I make some kind of a lite widgets, based on QObject because I want to construct interface from primitives like a Text, Image, Rect. For example, button can be realized with styled Rect with Text on it. TreeView also a big scope of primitives. QWidget is a very fat and slow for this task.
But i want to mix my lite widgets with standard Qt widgets, like as QGraphicsView do. And I want to use standard layouts with both Qt widgets and lite widgets.
So, I wrote my own QLayoutItem subclass for a lite widgets. But, size policy and stretch factors I can't provide to layout because no such virtual functions in QLayoutItem.
I think it's a design problem of the Qt itself. I've seen many casts to QWidget, casts to QGridLayout and QFormLayout in QLayout sources %) and so on... It's a very bad practice.