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. Why is heightForWidth ignored?
Forum Updated to NodeBB v4.3 + New Features

Why is heightForWidth ignored?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.6k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    chacham15
    wrote on last edited by
    #1

    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??]

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chacham15
      wrote on last edited by
      #2

      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.

      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