Python pyqt: background images - python

I'm using Python (2.7.3) and Qt designer (4.8.2) in Windows 7, and I'm new'ish to Qt designer:
How may I create a background image within a Form widget in Qt designer?
It doesn't matter if this takes up the entire screen or an area of the form (as demonstrated below). What I do need however is to superimpose objects such as QLineEdits and/or QLCDNumbers.
Ideally, I'd do this within Qt and not at run-time (a point and click solution would be a perfect for me).
I have generated this image in gimp quickly to demonstrate what I mean:

Found solution here:
https://www.youtube.com/watch?v=pzzccU9mErg [from 00:06:00 to 00:08:00]
Steps:
1/ Within Qt designer position a Qlabel within your widget
2/ Delete text in the text properties ('TextLabel' by deafult), and resize to image size wanted.
3/ Scroll to pixmap property and select intended image; click scaledContents is wanted
you'll now see your image within the widget

Related

How to have 2 QTreeview widgets side by side and resize

I am using QTDesigner to design an application (I am trying my hand at a dual pane file manager). I can't figure out how to have the 2 widgets side by side so that they both resize when I resize the application
A layout, as JRazor mentioned, is a good solution if you want your Tree Views to have always same size. If not, use a QSplitter
From the Qt documentation:
A splitter lets the user control the size of child widgets by dragging
the boundary between them.
QSplitter *splitter = new QSplitter(parent);
QListView *listview = new QListView;
QTreeView *treeview = new QTreeView;
splitter->addWidget(listview);
splitter->addWidget(treeview);
EDIT
Sorry I didn't notice that you are actually looking for a python solution. I have provided a C++ example code, but I believe that it's not that big difference doing it with python.
Use layout:
layout = QHBoxLayout(self)
layout.addWidget(left_tree)
layout.addWidget(right_tree)
If you want use QtDesigner: http://doc.qt.io/qt-4.8/designer-layouts.html

How to get coordinates of QToolBar icons in PyQt4 application?

I'd like to know how to set position of QCalendarWidget just below the button of ToolBar.
Currently, when user clicks a icon button inside red box,
then the below Calendar() instance is created and the instance is shown in the middle of screen.
What I want to implement is like the following.
You can refer full source code from here.
Any suggestion or advice will be appreciated.
This functionality is already provided by QDateTimeEdit, so you don't need a separate button for it:
def init_toolbar(self):
...
dtedit = QtGui.QDateTimeEdit()
dtedit.setCalendarPopup(True)
Qt Docs: QDateTimeEdit.setCalendarPopup.
This is usually done with a combination of using QWidget.geometry() or QWidget.rect() to get the size and position of a widget (in this case, the clicked button) and then using the QWidget.mapFromXXX and QWidget.mapToXXX series of functions, to transform those into global coordinates and then into widget coordinates that can be fed to QWidget.move()

PySide : "Dynamic" positionning of buttons on GUI?

I'm using python 2.7.5 on OSX 10.8. I'm learning PySide and trying to build a simple GUI.
I managed to use buttons (WOAAA!) used to chose a path or execute functions :
pathBtn = QtGui.QPushButton("FITS file path", self)
pathBtn.setToolTip('Choose the <b>path</b> to your FITS file')
pathBtn.clicked.connect(essai)
pathBtn.resize(pathBtn.sizeHint())
pathBtn.move(200, 100)
My problem is, when the program is running and I change the size of the window with the mouse cursor, the buttons don't move, don't adapt to the size variation.
I tried to find some answer (hell yeah google) and I understand that "QVBoxLayout" should do what I want (some kind of "dynamic" positionning, don't know if there's a specific name for that), but I didn't understand its syntax nor how to use it...
Any help appreciated!
In Qt widgets, layouts and the widget's size hints determine how things resize. The general procedure to layout a widget would be (for example):
dialog = QDialog()
layout = QVBoxLayout()
label = QLabel('This is a label')
edit = QLineEdit('This is a line edit box')
layout.addWidget(label)
layout.addWidget(edit)
dialog.setLayout(layout)
(*I cannot test this code here at work (no Qt/PySide), so consider this "pseudo code" :-)
This results in a dialog widget with a label and an edit box. If you resize the dialog widget, the layout and the resize properties of the widgets ensure that the label and edit box resize appropriately: horizontally both expand maximally, but vertically the edit will keep the same size while the label takes all the remaining space. This is because the resize hint of the edit box says it wants to keep its height (namely, one line of text).
If you do not specify a layout, your widgets (buttons, labels) don't do anything whenr resizing their parent widget, which is what you are observing. Hence, the solution is indeed the QVBoxLayout, use it as I described above.
By the way: for more complicated layouts, you probably want to use the Designer tool provided with Qt: this tool lets you see and test your GUI a priori.

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