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?



  • May be because QLayout is not widget, it only manages widgets.



  • Of course, QLayout isnt a widget, but why do an abstract class QLayoutItem and then climb directly to the QWidget... I dont understand this.

    ps. I want to implement own controls (like a spacer, not a QWidget subclass) and put them to standard QLayout..



  • just inherit your own class from QLayoutItem (as QSpacerItem)



  • I am exactly do this, but i can't provide sizePolicy to a layout, because no virtual sizePolicy in QLayouItem. I can't provide stretch factors too in my subclass. It's a very sad.



  • try to reimplement next functions:

    @QSize QSpacerItem::minimumSize() const

    QSize QSpacerItem::maximumSize() const@



  • Yes. I also think same as you. I can partially emulate sizePolicy using this functions. But it will still be a buggy code and i can't emulate a stretch factor in QSizePolicy (



  • [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.



  • Why QWidget is very fat and slow? Do you write application for desktop? or for slowly embeded system?



  • When I create 5000 widgets, for example in QScrollView, it's so slow (redrawing). When I create a same number of my controls redraws flow smoothly. I write app for a desktop.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.