Menu
  • HOME
  • TAGS

Displaying pyqtgraph and pyqt widgets on web

python,django,pyqt,saas,pyqtgraph

Here is what I have sort of put together by pulling several threads online: Ruby On Rails seems to be more popular than python at this moment. If you go python, Flask and Django are good templates. bokeh seems to be a good way of plotting to a browser. AFAIK,...

How to undo an edit of a QListWidgetItem in PySide/PyQt?

qt,pyqt,pyside

That tutorial you mentioned is really not very helpful. There are indeed many approaches to undo-redo implementation for views, we just need to choose the simplest one. If you deal with small lists, the simpliest way is to save all data on each change and restore full list from scratch...

PyQt SimpleHTTPServer: GUI freezes on starting server

python,multithreading,pyqt,multiprocessing,simplehttpserver

The issue with your examples that lock the GUI is that rather than passing a reference to the function when creating the thread, you are actually running the function immediately and the thread is never created. For example, you should be doing: server_thread=threading.Thread(target=start_server) Note that I drop the brackets on...

PyQT4 Datetime widget

python,pyqt,pyqt4

The problem is you're expecting a QtGui.Widget behaves as a QtGui.QLabel, your label_datetame class is not a QLabel, is a QWidget since its inherits from it. You should inherit your class from QLabel in order allow the other widgets (QLayout, QWindow, etc...) "talk" to it the "QLabel languaje". A QLabel...

Line edits at 0 when not used? PyQt

python,pyqt

Your code is going to raise an exception whenever the user enters anything that's not a number—including nothing at all. The nicest way to handle this is by validating the entry (and pre-filling it with something valid, like 0), so they can't click OK with something invalid in the box....

Still Freezing when using PyQt4 Thread

multithreading,pyqt,midi

Your thread is deliberately emitting more than one signal to execute the play() method in the main thread. Your play method must be running for a reasonable amount of time and blocking the main thread (it for instance has a time.sleep in it). You probably need to move the play...

How can I have an animated system tray icon in PyQt4?

python,qt,pyqt,pyqt4,system-tray

Maybe something like this. Create QMovie instance to be used by AnimatedSystemTrayIcon. Connect to the frameChanged signal of the movie and call setIcon on the QSystemTrayIcon. You need to convert the pixmap returned by QMovie.currentPixmap to a QIcon to pass to setIcon. Disclaimer, only tested on Linux. import sys from...

What's the difference between @pyqtSignature() and @pyqtSlot() pyqt decorators

python,qt,pyqt,pyqt4

The pyqtSignature decorator is part of the old-style signal and slot syntax, which was replaced by the new-style signal and slot syntax in PyQt-4.5. Both decorators serve the same purpose, which is to explicitly mark a python method as a Qt slot and specify a C++ signature for it (most...

Add custom attribute to QCheckBox widget

pyqt,attr,qwidget

You can just subclass the QCheckBox class. For example: class MyCheckBox(QtGui.QCheckBox): def __init__(self, my_param, *args, **kwargs): QtGui.QCheckBox.__init__(self, *args, **kwargs) self.custom_param = my_param Here we override the __init__ method which is called automatically when you instantiate the class. We add an extra parameter my_param to the signature and then collect any...

Displaying an image on pyqt

python,image,pyqt

You initialized everything properly, however you never set the label to be shown. def HandleQuestion(self): pic = QtGui.QLabel(self) pic.setPixmap(QtGui.QPixmap("Q107.png")) pic.show() # You were missing this. self.lbl3.move(0,190) self.SketchPad.resize(250,80) self.SketchPad.move(0,220) ...

QTableView / QTableWidget: Stretch Last Column using Qt Designer

pyqt,pyqt4,qt-designer,pyqt5

In the Qt Designer, Select the QTableWidget / QTableView and navigate to the Property Editor. Here, scroll down to the 'Header section' and enable horizontalHeaderStretchLastSection. ...

How can I center a label in the center of a QWizardPage?

python,qt,pyqt,pyqt4,wizard

Add your label in between two spacer items. Your vertical layout should also be laid out in its parent widget so it takes full size of the parent. QSpacerItem* verticalSpacer1 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); label = new QLabel(Form); label->setAlignment(Qt::AlignCenter); QSpacerItem* verticalSpacer2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer1);...

PyQt progress bar not updating or appearing until 100%

python,widget,pyqt,pyqt4

You can add: from PyQt4.QtGui import QApplication Then in your for loop: QApplication.processEvents() Your app is actually becoming unresponsive, you need to call processEvents() to process the events and redraw the gui. I am not overly familiar with pyqt but I imagine another alternative is using a thread....

How to call a function in pyside MainWindow from another python script

python,qt,pyqt,pyside,mainwindow

In one project i had to enable one module to do a callback to my Mainwindow module. The Controller of the Mainwindow view starts a new subprocess and retrieves the stdout out as well as the callback as soon as the program is terminated. I managed this in the following...

PyQt5 QSqlTableModel not updating changes to database

python,mysql,pyqt,pyqt5,qsqltablemodel

Fixed both my problems. pyqt documentation advices not to use setQuery. You should normally not call it(setQuery) on a QSqlTableModel. Instead, use setTable(), setSort(), setFilter(), etc., to set up the query. Updated code: from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel from PyQt5.QtWidgets import QTableView, QApplication import sys app = QApplication(sys.argv) db...

The event loop is already running

python,python-3.x,pyqt,pyqt4

I think the problem is with your start.py file. You have a function refreshgui which re imports start.py import will run every part of the code in the file. It is customary to wrap the main functionality in an ''if __name__ == '__main__': to prevent code from being run on...

How to re-use variable

python,qt,user-interface,pyqt

Just call path which returns p. if __name__ == "__main__": ui.enableBox(Interface, ui.path(Interface)) ...

Why does QTreeView not fire a Drop or Move event during drag and drop?

python,pyqt,qtreeview

You need to track events on the viewport, and filter DragMove and Drop: self.view.viewport().installEventFilter(self) def eventFilter(self, object, event): if object is self.view.viewport(): if event.type() == QtCore.QEvent.DragMove: print "Moved!" elif event.type() == QtCore.QEvent.Drop: print "Dropped!" return super(MainForm, self).eventFilter(object, event) ...

How to access a variable of a class created within another class, from outside either class

python,class,pyqt

print ex.btn_a1.iconPathAssigned since ex is your form instance (as you know from the line ex = Ui_Form())...

How to import resource file in PyQt and build with pyinstaller?

python,pyqt,pyinstaller

see this answer QRC file is an XML file that looks like below: <RCC> <qresource prefix="/images"> <file alias='filename.jpg'>images/filename.jpg</file> </qresource> </RCC> use it in .py file should be like this: pixmap = QPixMap(':/images/filename.jpg') ...

Using Py2app with a GUI from QT Creator

python,qt,user-interface,pyqt,py2app

This is happening because py2app would not be able to find files specified through string paths in the code. It will not include those files in the binary. You can do one of two things to solve your problem. 1) You have to convert your .ui file to .py file...

pyqt - copying image to QClipboard crashing program

python,pyqt

Constructing more than one QApplication is likely the cause of the problem (you should only have 1 per process). Rather than constructing a new QApplication, just request a reference to the existing once by using QApplication.instance()

How use PyQt without GUI?

python,pyqt,pyqt4

If you need the Qt EventLoop without a GUI you can use QCoreApplication instead of QApplication: http://pyqt.sourceforge.net/Docs/PyQt4/qcoreapplication.html From the docs: The QCoreApplication class provides an event loop for console Qt applications. This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there...

Adding tools to Scribble app with PYQT4

python,pyqt,qgraphicsview,qgraphicsscene

Your current code has two instances of a QGraphicsScene created inside View.__init__. One is a standard QGraphicsScene and the other is your subclass Action. But your view can only be attached to one scene, so one of these is redundant and not functioning correctly. You have attached it to the...

How to get function to run at specyfic time using python and PyQt not using Cron

python,qt,pyqt,periodic-task

You should use QTimer in Qt applications. Usually you don't need to care about specific update time, as the goal is regular periodic check. So the most straightforward approarch is to create a timer for each feed and set the update interval of each timer (e.g. 10 minutes). If you...

QFileSystemWatcher error handling with PySide/PyQt - Python 3.x

python,qt,pyqt,pyside,qfilesystemwatcher

As per ekhumoro's comments above, I've managed to solve this question using both the qInstallMsgHandler and sys.excepthook functions. import sys import os from PySide.QtCore import qInstallMsgHandler def myCustomHandler(ErrorType, ErrorContext): print("Qt error found.") print("Error Type: " + str(ErrorType)) print("Error Context: " + str(ErrorContext)) #Error logging code #Error emailing code os.execv(sys.executable, [sys.executable]...

Qt Widget with slider

python,qt,pyqt

So I took @ekhumoro advice and implemented this using layout and QScrollArea (thanks! That's what I was looking for!). Scrolling works as I wanted, but I suppose my implementation is not the ideal solution. ;) class MyDialog(QDialog): def __init__(self, strt, parent=None): QDialog.__init__(self, parent) self.smallWidgets = list() self.setMinimumWidth(450) self.setMinimumHeight(600) self.setupLayout() self.setupScrollArea()...

PyQt ToolTip for QTreeView

pyqt,tooltip,qtreeview

As you are using the QStandardItem and QStandardItemModel classes (which is what I would recommend!) you don't need to bother with the TreeModel class you have found. Creating your own model is rarely necessary, but for some reason tutorials often encourage you to do so. If you find something encouraging...

How can I disable a QCheckBox WITHOUT triggering an event?

python,pyqt,qcheckbox

You can simply block signals just before disabling the QCheckBox, and re-enabling them just after. Assuming chk is your QCheckBox object just do: chk.blockSignals() # then you change the checkbox as you want chk.unblockSignals() ...

Can a QListWidget have groupings?

qt,pyqt,pyqt4,qlistwidget,qtreewidget

to list items in groups here a simalar question: How to list items as groups in QListWidget if headeritems and normal items are different in one property they can be handled differently in slot. I'm not quite certain, if it's the way you want. I tried to place checked items...

PyQt4 - How to shrink the layout on Mac OSX?

python,osx,qt,layout,pyqt

To reduce the space between the widgets you can use QBoxLayout.setSpacing(). About the size of the buttons, you could try to adjust it by setting the margin or padding with style sheets. Personally I would set the stretch of the bt_bookmark to 0 (hbox_layout.addWidget(bt_bookmark, stretch=0)) and the stretch factor of...

Resizable PyQt widget displaying an image with fixed aspect ratio

qt,pyqt,qimage

The following QLabel-based widget that will preserve the aspect ratio of a pixmap assigned to it. It uses the heighForWidth method to return the preferred height of the widget given its width. This way, the widget naturally respects the aspect ratio of the pixmap when resized and scales it accordingly....

PyQt Enable/Disable elements in a QComboBox

python,python-3.x,pyqt,pyqt4,qcombobox

By default, QComboBox uses a QStandardItemModel, so all of the convenience methods of QStandardItem are available to you: cb_letter.model().item(2).setEnabled(False) ...

PyQt4 setParent vs deleteLater

pyqt,pyqt4

Probably the easiest way to see what's actually going on is to step through things in an interactive session: >>> parent = QtGui.QWidget() >>> child = QtGui.QWidget() >>> layout = QtGui.QHBoxLayout(parent) >>> layout.addWidget(child) >>> child.parent() is layout False >>> child.parent() is parent True So the layout does not become the...

How to get groups and roles of a QPalette in PyQt/PySide?

pyqt,pyside,qpalette

This can be done with standard python introspection techniques: for name in dir(QtGui.QPalette): if isinstance(getattr(QtGui.QPalette, name), QtGui.QPalette.ColorGroup): print(name) and the same can be done with QtGui.QPalette.ColorRole. But note that this will produce a few extra items that you might not be expecting. There are NColorGroups and NColorRoles. which give the...

Disable cmd opening from GUI (PyQt)

python,user-interface,cmd,pyqt,pyqt5

This appears to have been solved in the questions that I linked. For reference, the solution appears to be as follows: startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() ...

PyQT Qtabwidget hide and close certain tab

python,tabs,pyqt

You can remove the close button of the tabs that should not be closed. This is done by with the function setTabButton of QTabBar, like this: QtGui.QTabWidget.tabBar().setTabButton(0, QtGui.QTabBar.RightSide,None) Here, we set the button of the first tab to be None. With the same function, you could also create your own...

PyQt5: QTimer out of sync after minimizing window (OSX)

python,osx,pyqt,pyqt5

This is probably related to a feature of OS X called "AppNap" which will aggressively reduces timer triggering, and syncs them even between apps, to conserve battery life. You can turn it off via commandline on a per-app-basis using the command defaults write <domain> NSAppSleepDisabled -bool YES where <domain> is...

Pyqt: Graphics view next to another widget

python,layout,pyqt

You are forgetting to call the setLayout method after you've created the layouts. So in your mainWindowWidget.initScene method it should say: self.layout = QtGui.QHBoxLayout(self) self.setLayout(self.layout) Also add a setLayout to the sidePannel.initUI method and it should work. BTW: there is no need to define all your attributes as class attributes....

how to get the default size of a window in pyqt4

python,qt,pyqt

QWidget.sizeHint holds the recommended size for the widget. It's default implementation returns the layout's preferred size if the widget has a layout. So if your dialog has a layout, just use sizeHint to get the recommended size which is the default one.

Port C++ class to PyQt

python,c++,qt,pyqt,porting

The code defines a constructor for the DocumentWidget class, which inherits QLabel and requires a QWidget as parent. The equivalent PyQt code would be: from PyQt4 import QtCore, QtGui class DocumentWidget(QtGui.QLabel): def __init__(self, parent): super(DocumentWidget, self).__init__(parent) # or QtGui.QLabel.__init__(self, parent) self.currentPage = -1 self.setAlignment(QtCore.Qt.AlignCenter) ...

Pyqt Embedding Graphics object in Widget

python,layout,widget,pyqt

Your issue is that you don't specify a parent for the QGridLayout (in the mainWindowWidget class), so it isn't attached to a widget. This results in the layout (and all widgets contained within it) not being visible. Adding a parent to the layout reveals a second problem in that you...

PyQt: QDataWidgetMapper doesn't show any data in widgets

python-3.x,pyqt,pyqt4

Copying from comments for the sake of completeness: mapper.to First(), mapper.setCurrentIndex() or similar must be called after column mappings were established for mappings to show any data.

How to put a child window inside a main window(PyQt)

qt,pyqt,parent,childwindow

I found a way. I used self.show() instead of dialog.show() and self.mdiAreainstead of window.mdiArea. Now I close the window and show it again with the widgets I want. I want to find a way to just "refresh" the window. But this is subject for another topic. Thanks a lot guys....

PyQt 3.3.6: How to align text in a table?

python,pyqt

I understand that the characters used for the thousands separator and the decimal mark may differ between locales, but surely no locale could sensibly interpret 5.5.5 as a number? Given that, it's hardly surprising that Qt wants to treat it as ordinary text. But anyway, the docs for QTableItem suggest...

Layout management on PyQt4 Docks

api,pyqt,pyqt4,docking

QDockWidget already has a layout (as the error say) You should try something like this (pseudocode) grid = QWidget() layout = QGridLayout() ... add the widget to the layout grid.setLayout(layout) dock = QDockWidget() dock.setWidget(grid) ...

How to override Pyqt combobox ItemText method so it returns default python string instead of QString?

python,list,combobox,pyqt,pyqt4

You could just subclass QComboBox: class MyComboBox(QtGui.QComboBox): def itemText(self, index): return str(super(MyComboBox, self).itemText(index)) Note however that you may run into trouble if your combobox contains non-Ascii characters. Or you could try monkey-patching, but that is just plain ugly: def foo(combo): def wrapper(index): return str(QtGui.QComboBox.itemText(combo, index)) return wrapper _ui.ComboBox.itemText = foo(_ui.ComboBox)...

QGraphicsView vector edit: update path when moving node – properly?

python,qt,pyqt,vector-graphics,qgraphicsview

In the end I chose to just use the points coordinates on each move to create a new updated path from scratch and calling QGraphicsPathItem.updatePath() when a move happens. This avoid the need for low-level manipulation, something QPainterPath isn’t exactly made for anyway....

Converting 2D screen coordinates to 3D Coordinates in PyQT

qt,3d,pyqt,2d,2d-3d-conversion

To answer my own question: (x, y, z, vx, vy, vz) = self._display.View.ConvertWithProj(self.lastPos.x(), self.lastPos.y()) Gives the entire line of points that x and y can map to, with x, y, and z being one point, and vx, vy, and vz giving the parameterization of the line....

Understanding MVC in a QAbstractTableModel

model-view-controller,pyqt,qtableview,qabstracttablemodel

As stated in the comment, your model is your list of object. You should subclass QAbstractTableModel to use this list. Here's my code snippet for this: import sys import signal import PyQt4.QtCore as PCore import PyQt4.QtGui as PGui class OneRow(PCore.QObject): def __init__(self): self.column0="text in column 0" self.column1="text in column 1"...

Syntax highlighting not working from QMainWindow

qt,pyqt,qt4

You need to keep a reference to the highlighter. So just do: self.highlighter = Highlighter(editor.document()) EDIT: To be more precise: you need to keep a reference to the python part of your QSyntaxHighlighter subclass. The parent object passed to the constructor will take ownership of the highlighter, but Qt obviously...

PyQt5 QTextEdit auto completion

python-3.x,autocomplete,pyqt,qtextedit,pyqt5

an example here...that i've worked on... although it is in python3.3 and pyqt4. I guess it should not make much of a difference.. you will have to change from PyQt4 to from PyQt5 shortcut keys are Ctrl+Space to show suggestions and Ctrl+E to autocomplete the first avialable suggestion mMyTextEdit.py from...

PyQt, Python 3: Lambda slot assigning signal argument to a variable?

python,python-3.x,pyqt

I don't think you can (or should want to) do this with lambda. See the answer to the possible duplicate (that I reference under your question) for what you can do. One way to do something similar would be to simply define a single function which takes two arguments. The...

How can i create a searchbar in pyqt

python,mysql,user-interface,pyqt

QCompleter can do the auto complete part - here's a simple working example: import sys from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) model = QtGui.QStringListModel() model.setStringList(['some', 'words', 'in', 'my', 'dictionary']) completer = QtGui.QCompleter() completer.setModel(model) lineedit = QtGui.QLineEdit() lineedit.setCompleter(completer) lineedit.show() sys.exit(app.exec_()) You could maybe add a list widget that also shows...

Uppercase input in QLineEdit python way

python,pyqt,qlineedit

Try this, I believe this serves your purpose. I won't call it much pythonic. More like PyQt override. #minor code edit from PyQt4 import QtGui import sys #=============================================================================== # MyEditableTextBox- #=============================================================================== class MyEditableTextBox(QtGui.QLineEdit): #|-----------------------------------------------------------------------------| # Constructor...

How do I compile QScintilla and Eric6 on Linux?

python,linux,compilation,pyqt,qscintilla

The main problem is that you are linking against Qt4 rather than Qt5. This is why the QAbstractScrollArea and QPrinter headers are reported as missing, and why you later get the undefined symbol error. QScintilla uses a features file to control compile-time configuration, and its sources need to be patched...

Pyqt - Add a QMenuBar to a QMainWindow which is in another class

python-3.x,pyqt,pyqt5

QMainWindow comes with its default QMenuBar, but you cant set a new one with QMainWindow.setMenuBar() More informations in the Qt Documentation...

Inserting multiple QCheckBox into QTableWidget odd rows

python,pyqt,pyside,qtablewidget,qtablewidgetitem

This basic script creates an UI containing a 160*10 QTable and a QPushButton. Every odd row, a checkbox is added in the cell of the 10th column. Clicking on the button displays a list of the state of all checkboxes. States: 0: Unchecked 2: Checked There is a state 1...

Heights of QPushButton and QLineEdit differ under OS-X

qt,pyqt,pyside

I've found a workaround that works for me. When using a QToolButton instead of a QPushbutton the button has the same height as the line editor.

arange horizontal line of buttons in Pyside/PyQT/Qt

qt,button,layout,pyqt,pyside

This is easy to do with Tool Buttons. In Qt Designer: Create the tool buttons and set the text Put them in a horizontal layout Add a horizontal spacer to the beginning and/or the end of the layout Optionally, you could also: Set a minimum width/height Change the size-policy of...

Qt (PyQt) globally available slots?

qt,pyqt

How about implement singleton, that allow communication between components and gui, something like: #include <statuscontroller.h> StatusController::instance()->setStatus("Status string"); In this case only StatusController contain pointer to QStatusBar and available globally in gui thread. With QObject as base class for StatusController you could use signals and slots....

pyqt - Automatically update widget on user input

python-2.7,pyqt,pyqt4

The normal way of adding widgets to a Qt application is to use layouts. They will calculate the preferred size and location of your widgets and update this when needed, e.g. when widgets are added or when the window is resized (note what happens when you make your window smaller...

Wrong widget order using vbox layout PyQt

python,widget,pyqt

The problem is because you are adding self.pNames label to layout twice. #portion of your code ... self.layout.addWidget(self.pNames) # here self.layout.addWidget(self.polyNameInput) self.layout.addWidget(self.pNames) # and here self.layout.addWidget(self.polyTypeName) self.layout.addWidget(polyType) self.layout.addStretch() ... The first time you add the QLabel, it gets added before the LineEdit and when you add it second time, it...

Python - matplotlib - PyQT: plot to QPixmap

python,matplotlib,plot,pyqt

I have tried the following and that works: def testColourMap(cmap): sp = SubplotParams(left=0., bottom=0., right=1., top=1.) fig = Figure((2.5,.2), subplotpars = sp) canvas = FigureCanvas(fig) ax = fig.add_subplot(111) gradient = np.linspace(0, 1, 256) gradient = np.vstack((gradient, gradient)) ax.imshow(gradient, aspect=10, cmap=cmap) ax.set_axis_off() canvas.draw() size = canvas.size() width, height = size.width(), size.height()...

Change the background color of some lines in QPlainTextEdit

pyqt

The right way: fmt= QTextBlockFormat() fmt.setBackground(self.errorColor) while block.isValid(): if block.blockNumber() in self.lineError: QTextCursor(block).setBlockFormat(fmt) block= block.next() ...

Python crashes using pyqt, setPixmap and QLabel

python,python-2.7,pyqt

Strange, for me (Win7, 64-bit) the cut off size is closer to 300. I don't know why it behaves like this but in my case I can fix it by calling processEvents on the application, like this: class PixmapTest(QtGui.QWidget): def __init__(self, app): super(PixmapTest, self).__init__() self.app = app imglayout = QtGui.QHBoxLayout(self)...

Is a mutex really necessary in this piece of code?

python,pyqt,mutex

I would leave it where it is. If you're unlucky your reset/increment is performed by one thread in the small time window just after the countdown thread reads the counter and before it writes back the result of its decrement. It would then overwrite the updated value without even seeing...

QT Event filter for holding mouse button down

python,qt,pyqt

It wasn't that hard once I thought about it, but here it is def holdable(widget): class Filter(QObject): clicked = pyqtSignal(QWidget) def eventFilter(self, obj, event): if obj == widget: if event.type() == QEvent.MouseButtonPress: if obj.rect().contains(event.pos()): obj.heldDown = datetime.datetime.now() #return True elif event.type() == QEvent.MouseButtonRelease: if obj.rect().contains(event.pos()): if(obj.heldDown): diff = datetime.datetime.now() -...

PyQt5 resize only one child widget when window is resized

python,qt,layout,resize,pyqt

No matter what I tried, I could not make anything work for three widgets attached to a single splitter instance (I tried SizePolicy settings, QSplitter stretch factors, ...). So a tried to wrap it with few more QFrames and seems to work. But I'm still opened for solution for the...

Put a QLineEdit() into a QTreeWidgetItem()

python,python-3.x,pyqt,pyqt5

It should suffice to set your item flags to include ItemIsEditable: self.item.setFlags(self.item.flags() | Qt.ItemIsEditable) You can also configure the EditTriggers to start editing as you like, e.g. upon double-clicking an item: treeView.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked) Double-clicking an item in your treewidget should now bring up an editor - which by default is simply...

Creating check boxes dynamically inside the listview based on the layers loaded in QGIS

python-2.7,pyqt,pyqt4

I made the following changes in the main python file and that works. Thanks for the efforts. def addLayers(self): """ Adds Checkboxes inside the listview dynamically based on the number of layers loaded in QGIS. """ canvas = qgis.utils.iface.mapCanvas() allLayers = canvas.layers() if canvas.layerCount > 0: model = QStandardItemModel() for...

QVBoxLayout's 'setAlignment' method not working as expected

python,qt,pyqt,pyside,qvboxlayout

QGridLayout::addLayout has a fourth (optional) parameter alignment. The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell. So instead of setting the alignment of the QVBoxLayouts, set it when adding the layouts. def create_layout(self): .... mainLayout.addLayout(radioButtonSetALayout,0,0,QtCore.Qt.AlignTop) mainLayout.addLayout(radioButtonSetBLayout,0,1,QtCore.Qt.AlignTop) self.setLayout(mainLayout) ...

Refreshing a QWidget

python,qt,python-2.7,pyqt,vtk

To update the widget, you should repaint() it, but calling repaint() directly is not very good, so try: widget.update() From doc: This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop. This permits Qt to optimize...

How often are objects copied when passing across PyQt signal/slot connections?

python,pyqt,signals-slots,pyqt5

As suggested by @ekhumoro, I did try, and surprisingly I get a different result to what the test conducted in C++ reveals. Basically, my test shows that: objects are not copied at all, even when passed across thread boundaries using QueuedConnection Consider the following test code: class Object2(QObject): def __init__(self):...

PyQt QVariant with dictionary

python,pyqt

PyQt will try to convert to the corresponding C++ type if it can. For a dict, this means a QMap - but only if all the keys are strings. Otherwise, it just wraps a reference to the original dict (i.e. there is no implicit copying). For a list, the conversion...

Casting a QObject subclass instance

python,pyqt,pyqt4

All the methods Screenshot inherits from QPixmap will return a QPixmap, so you need to explicitly create and return an instance of Screenshot instead. The only real issue is to avoid inefficient copying. However, QPixmap provides a very fast copy-constructor for doing just that, so all you need is something...

PyQt, QComboBox with QStringModel cause QObject::startTimer: QTimer can only be used with threads started with QThread

python,qt,pyqt,qcombobox

I got the answer from here: Error in model view implemention of GUI in pyqt After add the model with a parentcombo.setModel(QStringListModel(string_list, combo)), the error is gone away....

How to get value of QtComboBox?

python,qt,pyqt,qt-designer

Where you say 'city' you should say 'self.city' so that city is attached to the object. Then later you can get its text as 'self.city.currentText()'.

How do I change each pixel

python,image-processing,pyqt,qimage

I'm not sure I understood what you want, but since you are new to Python, here go a few tips... Unpacking This code: pixelR = pixelR[0] pixelG = pixelValueTuple[1] pixelB = pixelValueTuple[2] Is the same as: pixelR, pixelR, pixelR = pixelValueTuple[:3] If you are sure len(pixelValueTuple) == 3, then it...

How to save a treeview as pdf in PySide/PyQt?

qt,pdf,pyqt,pyside

According to the docs, the variant of QWidget.render that has a QPainter as its first parameter expects a mandatory targetOffset of type QPoint as its second parameter. If I add an empty point it works for me (although the tree widget is printed very small). painter.begin(printer) try: self.view.render(painter, QtCore.QPoint()) finally:...

PyQt GUI order of operations

python,python-2.7,user-interface,pyqt,pyqt4

The GUI is not updated/drawn until control is returned to the Qt event loop. The event loop runs in the main thread, and is what handles interactions with the GUI and coordinates the signals/slot system. When you call a Qt function in a slot like clickStop1(), the Qt call runs,...

WARNING: All changes made in this file will be lost

qt,user-interface,pyqt

Since this is a generated file, it is a result, not a source. Thus: When you distribute your project, you shouldn't be distributing that file. So, whatever you do to the file, won't reach your customers anyway. Whenever your project is built and the source .ui file is changed, the...

How can I make link on web page in window using pyqt4?

python,qt,hyperlink,pyqt,pyqt4

It is of course good that you found answer, but there is special class, which allows you to open URL in default browser or files in default editors/players etc. It is QDesktopServices. For example: from PyQt5.QtGui import QDesktopServices from PyQt5.QtCore import QUrl class MainWindow(QMainWindow, Ui_MainWindow): def link(self, linkStr): QDesktopServices.openUrl(QUrl(linkStr)) def...

PyQT4: Adding combobox in Qtableview

combobox,pyqt,qt4,tableview

Does this need to be done using a QTableView or can you do it using a QTableWidget? Making the assumption that you can use the Widget vs the View, you can easily add a combobox (or any widget) to a cell. class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self,parent) self.table = QtGui.QTableWidget()...

Difficulties with re-using a variable

python,user-interface,pyqt

You have to declare variabile in the __init__ method (constructor) and then use it in your code ex: class projet(object): def __init__(self): self.valCouche = '' def nameCouche(self): valLissage = float(ui.valLissage.displayText()) return (valLissage) def choixTraitement(self): ui.okLissage.clicked.connect(p.goLissage) def goLissage(self, valCouche): if ui.chkboxLissage.isChecked(): self.valCouche = self.nameCouche() print(self.valCouche) # result is False os.system(r'"C:\Program Files\FME\fme.exe"...

PyQt4: set a default font?

fonts,pyqt

Neither Qt nor PyQt sets a default font: It's taken from the system settings. Overriding the user's fonts is very poor design, but if you must do it, use QApplication.setFont.

PyQt5: one signal comes instead of two as per documentation

python,pyqt,python-3.3,signals-slots,pyqt5

You only connected to one of the two signal overloads. Since you also didn't specify which overload you wanted, a default will be selected - which in this case will be valueChanged(int). To explicitly select both overloads, you would need to do: self.spb.valueChanged[int].connect(self.onValueChanged) self.spb.valueChanged[str].connect(self.onValueChanged) ... def onValueChanged(self, x): print("QSpinBox: value...

Logging python errors on raspberry pi

python,linux,pyqt,raspberry-pi

As it stands you're just capturing stdout. Modify your invocation to the following: sudo python appname.py >> logfile.log 2>&1 This will redirect both stdout and stderr....

Why aren't my QRadioButtons 'exclusive' after being added to separate QButtonGroups?

python,qt,pyqt,pyside,qradiobutton

I only have PyQt5 available for testing, but was able to reproduce your problem with it. When defining the layout in create_layout, buttonGroup1 and buttonGroup2 are deleted on return. You need to store these variables for them to exist after method return. For example this can be done by adding...

PyQt Not updating label

python,pyqt

You might need to force processing of events after changing the label text. Try adding: QApplication.processEvents() after setting the label text. Please note that for a reason not known to me, PyQt and PySide both tend to have problems with processEvents, which sometimes needs to be executed multiple times to...

How to switch between two windows in python using PyQt

python,python-2.7,pyqt,pyqt4

The instance of the settings window is local to the MainWindow.ShowSettings method. As such, it is quickly garbage collected because nothing keeps a reference to the window. You can fix this in two ways. The first is to specify a parent of the settings window when it is instantiated. The...