How to use Phonon::VolumeSlider in PyQt
In PyQt there's a widget called Phonon::VolumeSlider. I would like to know how I can take value from it if a user slides it. I know for push buttons you would type:
in the object class definition. But since you can't click an audio slider and my example says CLICKED.connect, I can't do that. Please tell me how I can make a line like this for my class. Thanks.
See also questions close to this topic
Python Kafka Streaming API - Binning
I am using python kafka stream binning example given in this, Python Kafka Streaming API
I am able to generate the data using generator.py file given under winton-kafka-streams/examples/binning/, whereas when i run the binning.py file from the same folder, i got the below issue. Could someone help me, to resolve this?
Change color of missing values in Seaborn heatmap
Consider the example of missing values in the Seaborn documentation:
corr = np.corrcoef(np.random.randn(10, 200)) mask = np.zeros_like(corr) mask[np.triu_indices_from(mask)] = True sns.heatmap(corr, mask=mask, vmax=.3, square=True)
How do I change the color of the missing values to, for example, black? The color of the missing values should be specified independent of the color scheme of the heatmap, it may not be present in the color scheme.
I tried adding
facecolor = 'black'but that didn't work. The color can be affected by e.g.
sns.axes_style("white")but it isn't clear to me how that can be used to set an arbitrary color.
Xpath + Scrapy + Python : data point couldn't be scraped
This is the XML structure:
<tr> <td> <font size="3"> <strong>Location:</strong> Hiranandani Gardens, Powai </font> </td> </tr>
I want to extract : Hiranandani Gardens, Powai
I tried with these:
Both returned an empty list.
Note: we must have to use the text of tag, i.e., "Location:". Otherwise, there are many other places on the site where the same XML structure is used. So, it'll fetch many more unnecessary things apart from the desired value if the text of strong tag is not used.
How to Terminate PyQt Application Properly
I would like to use the following code to export a couple of pictures.
My question is: how do I have to change the code to let the program terminate automatically after all pictures have been generated?
It is a different situation as described in What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)? because my class inherits from
GraphicsViewand this from
QtGui.QGraphicsView. The answers in the link above all inherit from other class(es).
import numpy as np from PyQt5 import QtWidgets from PyQt5.QtCore import pyqtSignal, pyqtSlot import pyqtgraph as pg import pyqtgraph.exporters from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph import GraphicsLayoutWidget from threading import Thread, Event import time # Routine to acquire and serve data # This might be a camera driver, notifying when a new frame is available def generate_data(callback, threadkill): for runner in range(5): width = 1600 data = np.zeros(width) data.fill(runner) my_var = callback(data, runner) time.sleep(0.01) print("callback called") class PyQtGraphTest(GraphicsLayoutWidget): # Signal to indicate new data acquisition # Note: signals need to be defined inside a QObject class/subclass data_acquired = pyqtSignal(np.ndarray, int) def __init__(self): super().__init__() self.exporter = None self.setWindowTitle('Test pyqtgraph paint signals') self.resize(640, 400) self.plot = self.addPlot() self.spectrum = self.plot.plot() self.plot.enableAutoRange(pg.ViewBox.XYAxes) # Connect the signal self.data_acquired.connect(self.update_data) # Make and start the background thread to acquire data # Pass it the signal.emit as the callback function self.threadkill = Event() self.thread = Thread(target=generate_data, args=(self.data_acquired.emit, self.threadkill)) self.thread.start() self.thread.join() # Kill our data acquisition thread when shutting down def closeEvent(self, close_event): self.threadkill.set() # Slot to receive acquired data and update plot @pyqtSlot(np.ndarray, int) def update_data(self, data, runner): if not self.exporter: # Here we are passing the exporter the GraphicsLayout object that is # the central item (ci) inside this GraphicsLayoutWidget. That in # turn contains the two PlotItem objects. self.exporter = pg.exporters.ImageExporter(self.ci) self.exporter.parameters()['width'] = 640 self.spectrum.setData(data) self.plot.autoRange() self.exporter.export(str(runner) + 'exported_image.png') if __name__ == '__main__': import sys app = QtWidgets.QApplication(sys.argv) window = PyQtGraphTest() window.show() if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): sys.exit(app.exec_())
Dynamic Widget Addition in PyQt
I'm new to PyQt and I'm trying to create a system which dynamically adds widgets when the user presses add.
I want the same self.comboBox widget to get added above the Add button. I will also make a remove button but I believe that will be no problem.
Moreover, I would like certain checkboxes to appear next to the self.combobox when the user chooses an option (aka option is not -Select-).
Finally, how can I store the user's choices in the checkboxes and the combobox? Do I declare a variable or what exactly?
My code was too much to read, so this instead:
class myWindow(QWidget): def __init__(self): super().__init__() self.init() self.organize() def init(self): self.label = QLabel("Label") self.comboBox = QComboBox(self) self.comboBox.addItem("-Select-") self.comboBox.addItem("1") self.comboBox.addItem("2") self.comboBox.addItem("3") self.addbtn = QPushButton("Add") self.addbtn.clicked.connect(self.addComboBox) def organize(self): grid = QGridLayout(self) self.setLayout(grid) grid.addWidget(Label, 0, 0, 0, 2) grid.addWidget(self.comboBox, 1, 2, 1, 3) grid.addWidget(self.addbtn, 2, 2) def addComboBox(self): #Code to add a combo box just like self.comboBox above addbtn and below all existing comboBoxes.
Pyqt5 stop QThread worker on QAction
hello I have QTheard worker that start with click at QAction.
.... self.start_update = QAction('&Start', self) self.start_update.triggered.connect(self._start_thread) self.stop_update.setVisible(True) self.stop_update.triggered.connect(self._stop_thread) self.stop_update.setVisible(False) ... ... def _start_thread(self): self.start_update.setVisible(False) self.stop_update.setVisible(True) self.myworker.start() ... ... def _stop_thread(self): self.myworker.stop() # That close app with error self.stop_update.setVisible(False) self.start_update.setVisible(True) ...
Please help how to close terminate
Workercorrectly. Atm worker have
run(logic) method. Maybe need to add some method for correct worker closing?
PyQT 4 Need help for adjusting to screen resolution
How can I make a window(without using a Layout) to resize depending on the screen resolution,and all the widgets resize with it? Or how to have a scrollbar without using layouts?
error: ‘class QComboBox’ has no member named ‘setCurrentText’;
I have met an error like this,
error: ‘class QComboBox’ has no member named ‘setCurrentText’; did you mean ‘currentText’? x_cn_num->setCurrentText(QApplication::translate("MainWindow", "0", 0, QApplication::UnicodeUTF8)); ^~~~~~~~~~~~~~
however, I checked the official documentation, "setCurrentText" is exactly a compatible member of QComboBox.
if you know the real reason and solutions, please give me some clues.
Qt - QFrame with dashes
What's the best/easiest way of creating a QFrame with a dashed border? I'm aware of QSS "dashed" border, but that doesn't look so good and I don't know of any options (dash width, etc.). I assume I might need to subclass the QFrame and override the paintevent? But that seems a bit over-complicated for a simple dashed line, so I thought I'd check SO before embarking on that adventure!