Why is heightForWidth ignored?



  • I am implementing the ability for a QWebView to change its size depending on the size of its contents and the width given to it. This is for the purpose of displaying an email (where you dont have navigation or dynamic content, etc.).

    QResizingWebView extends QWebView:
    @
    int QResizingWebView::heightForWidth(int width) const{
    QSize old_size = this->page()->viewportSize();
    this->page()->setViewportSize(QSize(width, 10));

    QSize result_size = this->page()->mainFrame()->contentsSize();
    int result_height = result_size.height();
    this->page()->setViewportSize(old_size);
    
    printf("QFW: Height = %d (for width %d)\n", result_height, width);
    fflush(0);
    return result_height;
    

    }

    QSize QResizingWebView::sizeHint() const{
    return QSize(-1, -1); //neccesary for use of heightForWidth
    }

    void QResizingWebView::resizeEvent(QResizeEvent *event){
    QWebView::resizeEvent(event);
    printf("O : Height = %d. Width = %d\n", event->oldSize().height(), event->oldSize().width());
    printf("N : Height = %d. Width = %d\n", event->size().height(), event->size().width());
    }
    @

    I get the following print outs:
    QFW: Height = 5970 (for width 117)
    QFW: Height = 2161 (for width 532)
    QFW: Height = 5970 (for width 117)
    QFW: Height = 2161 (for width 532)

    O : Height = -1. Width = -1
    N : Height = 5970. Width = 117

    QFW: Height = 2655 (for width 307)
    O : Height = 5970. Width = 117
    N : Height = 2985. Width = 307 [it appears that it is setting the correct width: but with a little additional height]

    [The screen first renders here, i then proceeded to resize it to fullscreen and get the following additional printouts]

    QFW: Height = 1992 (for width 1515)
    O : Height = 2985. Width = 307
    N : Height = 2985. Width = 1515 [what the heck? why is the height COMPLETELY off??]



  • This is a stupid mistake which was a result of my lack of sleep, sorry. The problem was that the parent widget had a sizePolicy of QSizePolicy::Expanding, QSizePolicy::Expanding.


Log in to reply
 

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