QScrollArea limiting layout geometry?



  • I have a custom layout class I am writing and it appears that no matter what I set the size of the parent widget, the geometry rect coming in has a height no larger than 8178. The widget that has the layout assigned to it is sometimes as tall as 200K and yet that never comes into the geometry call.

    Here is the code to create the widgets in my main window:

    scrollArea = new QScrollArea();
    contentView = new QFrame();
    LibraryLayout* ll = new LibraryLayout();
    ll->setMargin(10);
    ll->setSpacing(5);
    ll->setSizeConstraint(QLayout::SetMinAndMaxSize);
    
    QFrame* f = NULL;
    
    for (int i = 0; i < 5000; i++) {
        f = new QFrame();
        f->setBackgroundRole((i%2 == 0)?QPalette::Base:QPalette::AlternateBase);
        f->setFrameStyle(QFrame::Box);
        f->setMinimumSize(150, 200);
        ll->addWidget(f);
    }
    
    contentView->setLayout(ll);
    contentView->setBackgroundRole(QPalette::Light);
    contentView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    
    scrollArea->setBackgroundRole(QPalette::Dark);
    scrollArea->setWidget(contentView);
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
    this->setCentralWidget(scrollArea);
    this->resize(QSize(640,480));
    

    Here is where I resize it based on the window resizing:

    void MainWindow::resizeEvent(QResizeEvent *re)
    {
    QSize size = scrollArea->viewport()->size();
    QSize lsize = contentView->layout()->minimumSize();
    QSize cvs = contentView->size();

    cvs.setWidth(size.width());
    cvs.setHeight(size.height());
    
    if (cvs.height() < lsize.height()) {
        cvs.setHeight(lsize.height());
    }
    
    contentView->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
    contentView->setMinimumSize(cvs);
    contentView->resize(cvs);
    

    }

    My custom layout returns the correct minimumSize but the rect for setGeometry is never larger than 8178. Not sure where that magic number comes from or why it isn't larger?

    The weirder things is that after the resize call on the contentView, the geometry for the contentView is also limited to 8178 high.



  • DOH, let's clean that up:

    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    scrollArea = new QScrollArea();
    contentView = new QFrame();
    LibraryLayout* ll = new LibraryLayout();
    ll->setMargin(10);
    ll->setSpacing(5);
    ll->setSizeConstraint(QLayout::SetMinAndMaxSize);
    
    QFrame* f = NULL;
    
    for (int i = 0; i < 5000; i++) {
        f = new QFrame();
        f->setBackgroundRole((i%2 == 0)?QPalette::Base:QPalette::AlternateBase);
        f->setFrameStyle(QFrame::Box);
        f->setMinimumSize(150, 200);
        ll->addWidget(f);
    }
    
    contentView->setLayout(ll);
    contentView->setBackgroundRole(QPalette::Light);
    contentView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    
    scrollArea->setBackgroundRole(QPalette::Dark);
    scrollArea->setWidget(contentView);
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
    this->setCentralWidget(scrollArea);
    this->resize(QSize(640,480));
    

    }
    @

    and on resize:

    @
    void MainWindow::resizeEvent(QResizeEvent *re)
    {
    QSize size = scrollArea->viewport()->size();
    QSize lsize = contentView->layout()->minimumSize();
    QSize cvs = contentView->size();

    cvs.setWidth(size.width());
    cvs.setHeight(size.height());
    
    if (cvs.height() < lsize.height()) {
        cvs.setHeight(lsize.height());
    }
    
    contentView->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
    contentView->setMinimumSize(cvs);
    contentView->resize(cvs);
    

    }
    @



  • After doing a LOT of digging and trying to figure things out by implementing some of my own scroll area type of system, it appears that I get random resize events with a max height of 8K. This is while minimumHeight is returning 32K!

    Also, the documentation form move states that only a moveEvent is generated. However, I seem to get a resizeEvent immediately before the moveEvent and this is where the 8K is coming from.

    Anyone? Any ideas what is going on here?



  • OK, it appears that this is in some way related to running on OS X. I've been debugging through the source and found out that qwidget_mac.mm is clipping view frames to 16bit coords. In fact, these two defines at the top of the file map almost exactly to values I see my sizes being changed to:

    @
    #define XCOORD_MAX 16383
    #define WRECT_MAX 8191
    @

    So, the question is how do I get around this? What options do I have in Qt to get this working so that I can display and scroll widgets that have sizes/positions > 16 bits?


Log in to reply
 

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