Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt4. Why no sizePolicy virtual method in QLayoutItem?
QtWS25 Last Chance

Qt4. Why no sizePolicy virtual method in QLayoutItem?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    navrocky
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • N Offline
        N Offline
        navrocky
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexander
          wrote on last edited by
          #4

          just inherit your own class from QLayoutItem (as QSpacerItem)

          1 Reply Last reply
          0
          • N Offline
            N Offline
            navrocky
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alexander
              wrote on last edited by
              #6

              try to reimplement next functions:

              @QSize QSpacerItem::minimumSize() const

              QSize QSpacerItem::maximumSize() const@

              1 Reply Last reply
              0
              • N Offline
                N Offline
                navrocky
                wrote on last edited by
                #7

                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 (

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    navrocky
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alexander
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        navrocky
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved