PyQT4 QWebView not resizing correctly - python

I have a QWebview in a grid layout, along with other widgets. When the user resizes the window, the QWebview doesn't resize, but the other widgets do. How can I make the QWebview resize correctly?

Most likely you're not using correct sizePolicy. Take a look here http://doc.qt.nokia.com/4.6/layout.html
Does using other widget in place of QWebView change anything?

in the dialog class's resizeEvent, one that extends QDialog, call webView->setGeometry, and this->resize, this->update.
hint: check if size changed via the QResizeEvent *ptr

Related

What is the best way to add regular widgets on top of a QGraphicsView?

I'm researching refactoring a tkinter app that currently uses tkinter.Canvas. The Canvas reacts to user input by creating windows over the canvas, which are made of regular tkinter widgets.
I haven't seen the equivalent method in QGraphicsView to tkinter.Canvas.create_window, wihch creates a canvas bound item that can then be used for building a regular interface.
Basically I'm looking for the right way to, say, right click on the View and get a popup window on top that I can deal with. Hopefully not bound to the scene, either, so that if I have multiple views on the scene the window only appears over the original View.
Because I'm new to Qt I'm out of my depth. Perhaps the widget that contains the View can receive the clicking event and proceeds to layout another widget in absolute terms over the QGraphicsView?
Any help is appreciated. Thanks!
I Found how to do it:
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (
QApplication,
QGraphicsScene,
QGraphicsView,
QGraphicsWidget,
)
app = QApplication(sys.argv)
scene = QGraphicsScene()
view = QGraphicsView(scene)
view.resize(400, 300)
window = QGraphicsWidget(None, Qt.Window)
window.resize(200, 200)
scene.addItem(window)
view.setScene(scene)
view.show()
sys.exit(app.exec())
Notice that unlike tkinter although you can add a regular widget to the QGraphicsScene directly with scene.addWidget, there are some limitations.
The method scene.addWidget returns a QGraphicsProxyWidget which is what can be positioned on the scene. And the layout of these widgets are different to the ones of regular widgets.

Rescaling the absolute coordinate x,y values of self items in order to resize items fit into different resolutions [duplicate]

I want to have a small QFormLayout that grows to fill its parent widget.
I created a new .ui file using the QWidget template in Qt Designer. I put a QFormLayout inside that 'window', then put some controls inside that QFormLayout.
This all works reasonably well, but the QFormLayout always stays at the size I set in Qt Designer. I would like the QFormLayout to fill its parent widget and grow/shrink with it.
How can I accomplish that?
In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout.
Then your QFormLayout will automatically resize.
Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget!
See also
Controls insist on being too large, and won't resize, in QtDesigner
I found it was impossible to assign a layout to the centralwidget until I had added at least one child beneath it. Then I could highlight the tiny icon with the red 'disabled' mark and then click on a layout in the Designer toolbar at top.
The accepted answer (its image) is wrong, at least now in QT5. Instead you should assign a layout to the root object/widget (pointing to the aforementioned image, it should be the MainWindow instead of centralWidget). Also note that you must have at least one QObject created beneath it for this to work. Do this and your ui will become responsive to window resizing.
You need to change the default layout type of top level QWidget object from Break layout type to other layout types (Vertical Layout, Horizontal Layout, Grid Layout, Form Layout).
For example:
To something like this:

PySide : How to get a QTabWidget to resize with the window?

I'm quite new to Python, and I'm developing an app with the PySide library.
I have a QTabWidget in which I will later define buttons/labels/... with some layouts. The question is simple : I'd like to have my active tab filling the window horizontally and vertically, even when I resize the window. For now its size is determined by the widgets I put in. Even with addStretch(1) in a QHBoxLayout or QVBoxLayout I can't get it to expand.
Is there an easy way to do this (I'm not a Python expert yet) ?
Any help will be highly appreciated.
If your main window is QMainWindow then it is enough to insert QTabWidget with mainwindow->setCentralWidget() - by default it will use all available space.
In other case, to have QTabWidget to follow the resizing/geometry change of parent widget, it is enough to make some layout on the parent widget and just insert QTabWidget there.
Code is approx (in Qt):
QWidget * dialog = ...
QTabWidget * tabs = new QTabWidget;
QVBoxLayout * vbox = new QVBoxLayout;
vbox->addWidget(tabs);
dialog->setLayout(vbox);
dialog->show();

Qwebview, how to resize it with window/

I've got an QWebView object inside my project and i want it to resize whenever i am resizing a main window. How to achieve that?
http://pastebin.com/3wcUygvb <- That's the ui code/
It looks like you've put all your widgets in layouts, but you haven't set a layout on the main form.
In Qt Designer, right-click on a blank area of the form and select Layout/Layout in a Grid.
Then save and re-compile with pyuic4.

pyqt: controlling a border widget

In pyqt: how to put a border frame around a widget I created a border around a widget. I'd now like to be able to control that border from the underlying program.
1) The base widget has a class name in Qt Designer and uses that class name in the program. How do I give a class name to my border widget?
2) I've set background color and margins in Qt Designer for the border widget. How do I set these in the program (overriding the Qt Designer settings)?
The name of the widget can be set in the Property Editor with the objectName property. The class name (e.g. QWidget) cannot be changed.
The background colour can be set using the setStyleSheet method.
Tip: A lot of these kinds of questions can answered by using pyuic4 to convert the ui file to a python module, so you can "see how its done". To do this, run the following command in a console:
pyuic4 -o output.py source.ui
The generated code is usually a lot more verbose than it needs to be, but it should give you a good idea of how to proceed.

Categories

Resources