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);...

you just have to make arguments for it and pass it into the class instance. then assign it to self.date, this makes it accesible across the class instance: class window(QtGui.QWidget): def __init__(self, parent = None): QtGui.QWidget.__init__(self, parent) self.setGeometry(100, 100, 500, 200) self.setWindowTitle('Hello') self.label = QtGui.QLabel(u'WoRLd', self) self.Layout = QtGui.QVBoxLayout() self.Layout.addWidget(self.label)...

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...

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...

The error message suggests you are using multiple threads in an unsafe way. You should never attempt to directly update gui elements from outside the main thread. The simplest way to safely communicate between threads is to use signals....

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...

I think what you're looking for is QT_TR_NOOP (or QT_TRANSLATE_NOOP if you need to provide context). This will mark a string literal as needing translation (i.e. so that it is picked up by pylupdate), but it does not do any translation at runtime (nor import time). Thus: from PyQt4.QtCore import...

Create an instance of Dialog in the openDialog method, so that you can access its attributes directly. That way, the two classes can operate more independently, and you won't need to access the Window class from within the Dialog class: def openDialog(self): dialog = Dialog(self) dialog.label.setText(self.value.text()) dialog.exec_() print(dialog.label.text()) class Dialog(QtGui.QDialog):...

A signal in PyQt is just a call to another callable object (method, function, functor), with some data. It is not the same as an electronic signal from, say, a USB connector. However, if you have a driver that reads a USB device's state at some frequency F, then all...

You need to connect the signal before the thread starts, and hence before the signal is emitted. If you want to show a dialog when the worker thread completes, just use the finished signal: class Requests(QtCore.QThread): def run(self): # do some work... print 'work finished' ... self.c = Requests() self.c.finished.connect(self.open_window)...

Qt (and other GUI toolkits) believe in parenting. The have one window or widget within another, set its parent. Note that you should be calling show on the outer one. import sys from PyQt4 import QtGui, QtCore class MyView(QtGui.QGraphicsView): def __init__(self, parent=None): QtGui.QGraphicsView.__init__(self, parent=parent) self.scene = QtGui.QGraphicsScene(self) self.item = QtGui.QGraphicsRectItem(300,400,100,100)...

AxisItem is not designed to do what you want. It has no knowledge of the data in your plot; it only knows the min/max values along the axis. You will need to either call AxisItem.setTicks() or override AxisItem.tickValues() to display the actual values of your data.

If you are using the QtDesigner, then its really easy. Have a look at layouts like vertical layout, horizontal layout Follow step: 1. Add layout to your main window. 2. Right click main window and click 'layout vertically' as you want button below the text area 3. Then add(drag-n-drop) your...

I solved it myself. In the code above the program itself generates a number between 0-10( in the update_figure method ). Supose the number is four. This means that on the wedge: theta1 = 180-number/10*179 #as always theta2: theta2 =180 after 5 seconds the program generates another number( for example:...

The crash happens because you are interacting with the Qt GUI from a secondary thread. You are only allowed to interact with the GUI from the main thread (see the Qt documentation). You have two options: Switch to a PyQt QThread, and emit a signal from the thread. If the...

You can use a QScrollArea. Put your GridLayout in a Widget and put that Widget in a ScrollArea. Mind the Notes in the documentation: When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget...

Solved! I found a similar question here: http://qt-project.org/forums/viewthread/9024 The libraries (when installed through Canopy) is in /Users/[USERNAME]/Library/Enthought/Canopy_64bit/User/lib Apparently they should be in /Library/Frameworks After copying them here it works......

The reason is that worker thread emit a signal, this signal could not directly bind to an UI slot, but you need to bind it to a general slot, then you call the UI slot to upgrade. As I don't have all your code, so Ｉ write a similar file...

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...

This is just a guess, because I cannot test it myself, but you could try loading the font before setting the stylesheet: app = QtGui.QApplication(sys.argv) QtGui.QFontDatabase.addApplicationFont('path/to/font') # or load the font data directly # QtGui.QFontDatabase.addApplicationFontFromData(fontdata) stylesheet = open('mystylesheet.qss').read() app.setStyleSheet(stylesheet) ...

You can execute an UPDATE statement just as you now execute your INSERT: cnxn = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=C:\\Users\\...............(file location)') cursor = cnxn.cursor() cursor.execute("UPDATE progress SET CockpitDrill = ? WHERE progress_primarykey = ?", newcockpitdrillvalue, oldprimarykeyvalue) cnxn.commit() Does that help? "progress_primarykey" is the assumed name I've given to the...

Firstly, the event filter needs to be set by the object you want to watch: points.installEventFilter(self) Secondly, the event you need to listen for is MouseMove not HoverMove: if event.type() == QtCore.QEvent.MouseMove: Finally, you need to enable mouse-tracking on the target widget: class DrawingPointsWidget(QWidget): def __init__(self): super(QWidget, self).__init__() self.setMouseTracking(True) ...

The difference between tr and trUtf8, is that the latter explicitly declares that the encoding is UTF-8. On its own, tr implies nothing about the encoding of the string, and so you either must only ever pass it ascii strings, or explicitly set an appropriate encoding using setCodecForTr. But as...

In one final act of desperation I tried installing SIP and PyQt4 directly in the virtualenv and now autocomplete works! So basically I: Activated the virtualenv through the command line Made the dist-packages folder in the lib folder in the virtualenv. You can probably call this folder anything you want....

Two problems in your code: You don't create an instance of the class MyForm. The buttons are created in the class Ui_Dialog but you try to access them from MyForm. If you want to access the buttons in MyForm, you have to create an instance of Ui_Dialog in MyForm, like...

You're forgetting to set it to the widget or main window, so since the QComboBox is the last one made, it's the only one displayed. Basically, everything is added to the layout, but the layout is "free-floating", and so it does not display properly. You need to bind the layout...

Matplotlib uses its own event so that they are independent of the UI toolkits (wx-windows, Qt, etc). Therefore the wxcursor_demo is easily adapted to Qt, as is your case. First add the following line to the constructor of your Canvas class self.mpl_connect('motion_notify_event', self.mouse_moved) This will call the mouse_moved method every...

You will need to add more Qt widgets (like QLineEdit or QSpinBox) so the user can specify the values. Then, when the plot button is clicked, you should instantiate new Mechanical_system and Calculus objects with the updated parameters (read them from the relevant Qt widgets you will add to your...

you can repaint the listwidget in the loop: def insertItem(self): for i in range(1,100): self.listWidget.addItem(str(i)) self.listWidget.repaint() with QTimer you can control the delay between 2 items. Edit: Perhaps i didn't understand your question correctly: you can add all items, hide them and then set them visible item by item: import...

This: timer.timeout.connect(instrument.update()) should probably be timer.timeout.connect(instrument.update) The former calls the function immediately while executing that line; the function returns None, which causes error in .connect. The latter just connects that function to the timeout slot. The first invocation of instrument.update should happen after 5 seconds...

Solved. Firstly I used the correct Python syntax instead of the C++ syntax as pointed out by ekhumoro. self.ui.CreateStuDOB.setMinimumDate(QDate.currentDate()) Then I correctly imported QDate using: from PyQt4.QtCore import * ...

a = QtCore.pyqtSignal(object) creates an attribute b = {'x': QtCore.pyqtSignal(object)} is storing an QtCore.pyqtSignal(object) object in an attribute of the object, so it will not be an attribute itself....

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...

The PyQt (Or generally speaking, the UI development) usually requires put the long-time run function into backend thread, so this will not blocking your UI thread, make it able to response the UI update/User interactive. so in this case, you need to put "someprocess" into backend thread(possibly inherit from QThread),...

Found a better way to debug this: right click on the app file, "view package contents", MacOS > select the executable with the same name as the file given in setup.py (for me this was main). Error I then got: QWidget: Must construct a QApplication before a QPaintDevice I fixed...

The addStep and subtractStep slots are deprecated members of QSlider. They are only there to provide backwards compatibility with Qt3. It seems you must be trying to run the example script using builds of Qt4/PyQt4 that do not include such deprecated APIs. The documentation suggests using the setValue slot instead....

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....

Please allow me to give a few tips on how to ask better questions before I answer your question. You're not getting many replies because your code example is too large and because we cannot just copy-paste-execute it and reproduce the problem ourselves. Next time make a minimal but complete...

Plotly is primarily developed to make graphing in a browser easy. I don't think it can be embedded into a UI framework like PyQT or Tkinter. Plotly has a enterprise version which works in our company network without a internet connection. PyQtgraph or MatPlotLib may be an option for you...

Thanks to Trialarion's comment to my question, I found the solution here. For anyone interested, here's the python code that displays images in sync with the screen refresh rate: import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtOpenGL import * app = QApplication(sys.argv) # Use a QGLFormat...

As you've discovered, setText doesn't do any validatation. So, instead, use insert: text = index.model().data(index, QtCore.Qt.DisplayRole) editor.clear() editor.insert(text) The other error is caused simply because you did not import QVariant, and so you can't use it. The easiest fix is to just omit it altogether (PyQt will automatically convert to...

I wasn't able to figure out how to hide the empty space so instead I'm just using a QTabBar + QStackedWidget which is quite easy to implement. In order to make one like a QTabWidget all you need to do is connect QTabBar.currentChanged to QStackedWidget.setCurrentIndex: self.stacked = QtGui.QStackedWidget() self.tabBar =...

I'm unable to reproduce this except with overloaded PyQt methods that have a specific combination of call signatures. Only when one signature has a single argument, and another has a single argument and the rest keyword arguments with default values, does this bug seem to be hit. There are exactly...

You need to block the execution of the program after you call window.show() so that the window object remains active otherwise it will be garbage collected. app.exec_() does this for you. {__author__ = 'Jay' import sys from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) window = QtGui.QWidget() window.show() app.exec_()} # added...

I'm not really sure why this wasn't working, or why my method fixed it, but I did 2 things to prevent the menu messing up: 1. I had been loading another main window before loading this one which was a smaller setup window. I now load this only when needed....

The reason that nothing is updating is that you're trying to use pyplot methods for a figure that's not a part of the pyplot state machine. plt.draw() won't draw this figure, as plt doesn't know the figure exists. Use fig.canvas.draw() instead. Regardless, it's better to use fig.canvas.draw() that plt.draw(), as...

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...

The mouse device driver. If you change mouse settings on the configuration panel of your system you will see a behavior difference. The window system send those events to the main process, which are handled by the QApplication and then propagated to the right widget. Unless no event filter has...

Simple Way for Dummies Add a QLineEdit, and set it frameless by QLineEdit::setFrame Add a QLabel with background color in white (by stylesheet) and a icon Combine the line edit and the label with a layout, set spacing to 0 Set placeholder text with QLineEdit::setPlaceholderText Result Advanced Way Check this...

The question could be solved using selenium-python (thanks to @Juca suggestion to use selenium). Once installed (pip install selenium) this code makes the trick: from selenium import webdriver # initiate the browser. It will open the url, # and we can access all its content, and make actions on it....

Using smitkpatel's comment... I found a setCompleter example which works. It was posted by flutefreak at QComboBox with autocompletion works in PyQt4 but not in PySide. from PyQt4 import QtCore from PyQt4 import QtGui class AdvComboBox(QtGui.QComboBox): def __init__(self, parent=None): super(AdvComboBox, self).__init__(parent) self.setFocusPolicy(QtCore.Qt.StrongFocus) self.setEditable(True) # add a filter model to filter...

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...

Use the model to iterate over the items: model = self.listView.model() for index in range(model.rowCount()): item = model.item(index) if item.isCheckable() and item.checkState() == QtCore.Qt.Unchecked: item.setCheckState(QtCore.Qt.Checked) ...

You want the QMutex class. Qt uses the QtCore.QMutex.lock() and unlock() functions to lock and unlock QThreads. Here's an example: https://github.com/Werkov/PyQt4/blob/master/examples/threads/waitconditions.py EDIT: They're fairly similar although there are subtle differences. http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ http://doc.qt.io/qt-4.8/qmutex.html The QMutex class effective can support both threading.Lock and threading.RLock behavior. Both these should...

I'm not 100% clear what your problem is (are you getting an exception? Does it run but you get unexpected output?), but this line looks like the culprit: self.x,y = self.cursor.pos() This will create x as an attribute of self, and then create a local variable y that has no...

To convert one QString in Python 2, do this: self.name = unicode(self.new_label.text()) To automatically convert all QStrings, put this at the beginning of your code: import sip sip.setapi('QString', 2) # must be before any pyqt imports from PyQt4 import QtCore, QtGui If you do this, there's no need to keep...

Currently we could not change characters for tabs and white space. This characters hardcoded in Qt source for QTextLayout: QChar visualTab(0x2192); ... QChar visualSpace((ushort)0xb7); More info in source for QTextLayout on GitHub. You can create feature request for tabs and white spaces custom characters. IMHO this feature will be useful...

While Macport should have been able to use its own tools, it needed some help. Reading the error message and consulting python configure-ng.py --help gave me the solution python configure-ng.py --sip /opt/local/bin/sip-3.4 which lead to a successful compilation....

The simplest and standard way is to use a tooltip. Every widget in Qt has a toolTip property you can use class mainWindow(QtGui.QWidget): def __init__(self): super(mainWindow, self).__init__() self.layout = QtGui.QVBoxLayout() self.label1 = QtGui.QLabel() self.label1.setText("Name") self.lineEdit1 = QtGui.QLineEdit() self.lineEdit1.setToolTip("This is a ToolTip") self.label2 = QtGui.QLabel() self.label2.setText("Age") self.lineEdit2 = QtGui.QLineEdit() self.lineEdit2.setToolTip("This is...

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...

If you want to schedule jobs that will interact with the user, you have to use Camelot Actions, which have their own method for executing functions in the model thread, posting the result to the GUI thread, and back... But you don't need that, you just need to run jobs...

The stateChanged signal sends the checked state, so the slot could be re-written as: def selectAll(self, state=QtCore.Qt.Checked): """Select All layers loaded inside the listView""" model = self.dlg.selectAllCheckBox.model() for index in range(model.rowCount()): item = model.item(index) if item.isCheckable(): item.setCheckState(state) (NB: if all the rows in the list-view have checkboxes, the isCheckable line...

There are two issues with the coordinates you are using to place the QGraphics...Items. The first is that the coordinates from QCursor are global screen coordinates, so you need to use self.mapFromGlobal() to convert them to coordinates relative to the QGraphicsView. Secondly, you actually want the coordinates relative to the...

It looks like you need to add the layout to the tab, rather than the tabwidget: for name in types: tab = QtGui.QWidget() typetab.addTab(tab, name[0]) typetablayout = QtGui.QGridLayout(tab) ... # typetab.setLayout(typetablayout) ...

If Python2 is used with PyQt4, then classes like QString and QVariant will be available by default. However, the default for Python3 is to eliminate these classes and use the equivalent python types instead. These defaults can be overridden by using the sip module, like this: import sip # switch...

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...

Calling setDefaultSuffix on an instance of QFileDialog has no effect when you use the static functions. Those functions will create their own internal file-dialog, and so the only options that can be set on it are whatever is made available via the arguments. Of course, setDefaultSuffix will work if the...

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...

I don't really see how this would be in any way an improvement over a combo-box, especially if there's more than a few strings. However, if you really want it, you just need to subclass QSpinBox and reimplement textFromValue and valueFromText: class StringBox(QtGui.QSpinBox): def __init__(self, strings, parent=None): super(StringBox, self).__init__(parent) self.setStrings(strings)...

In order to add code to a UI generated with QtDesigner, you must generate a .py file using pyuic: pyuic myform.ui -o ui_myform.py This ui_myform.py file, contains generated code that you should not edit, so later you can change your .ui file with QtDesigner, re-run pyuic, and get ui_myform.py updated...

You might want to insert an empty widget, before the last one and then disable it and set it to transparent. That achieves what you want. Attaching an example code for that. from PyQt4 import QtGui import sys def main(): app = QtGui.QApplication(sys.argv) tabW = QtGui.QTabWidget() tabW.setStyleSheet("QTabBar::tab:disabled {"+\ "width: 300px;"+\...

raw_input uses synchronous/blocking IO without giving Qt a chance to continue processing events in the background. Qt isn't really prepared for it's processing to be halted in this way. In theory it should just resume when raw_input is finished. But maybe in the meantime a timeout occurred or something like...

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,...

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...