views:

26

answers:

1

Even if I set the geometry for the QWebView it occupies the whole left over screen.

alt text Even worse if I maxmize the window, there is a gap between the two widgets

alt text Below is my code I wrote:

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *

class twsearchbox(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        hbx = QHBoxLayout()        
        self.setLayout(hbx)
        self.resize(1024,800)
        self.setWindowTitle('layout test')

        tbx = QTextEdit()
        tbx.setGeometry(0,0, 300, 550)
        tbx.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        hbx.addWidget(tbx, 0 , Qt.AlignLeft)

        wv = QWebView()
        wv.load(QUrl('twsearch_template.html'))
        wv.setGeometry(0,0,300,550)
        wv.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        hbx.addWidget(wv, 0 , Qt.AlignLeft)
A: 

I investigated this in code (in c++) and found it a bit puzzling until finally I took a look at the source code for QWebView. It seems that QWebView::sizeHint() is hard coded to 800 x 600 (Qt 4.6).

This seems a bit odd to me but I'm not sure enough to report a bug for it. If somebody can post a comment to confirm or deny the correctness of it, that would be good :)

In any case, you should be able to override this behavior by setting min/max height/width as needed.

Also, to explain the other behavior you see, even if the QWebView was the width you specified (300), you would see a gap as the layout tries to break the horizontal space into equal sizes. With the QWebView defaulting to 800 wide, the layout is stealing space from the left box to satisfy the size needed for the right box. If you had a wide enough screen, you would eventually see both halves equalize in size as you stretched the window horizontally.

Arnold Spence