qlabel

how to show picture and text in a label (PyQt)

淺唱寂寞╮ 提交于 2019-12-18 07:24:42
问题 I need to show a picture and text in a label, and this is my code: import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class MyLabel(QLabel): def __init__(self): super(MyLabel, self).__init__() def paintEvent(self, QPaintEvent): pos = QPoint(50, 50) painter = QPainter(self) painter.drawText(pos, 'hello,world') painter.setPen(QColor(255, 255, 255)) class Window(QWidget): def __init__(self): super(Window, self).__init__() layout = QHBoxLayout(self) self

make QLabel clickable using PyQt5

荒凉一梦 提交于 2019-12-17 10:07:08
问题 I have a Qlabel filled with QPixmap and I want to start a process/function once this label clicked. I had extended QLabel class as follows: from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * class QLabel_alterada(QLabel): clicked=pyqtSignal() def __init(self, parent): QLabel.__init__(self, QMouseEvent) def mousePressEvent(self, ev): self.clicked.emit() Then, in my pyuic5-based .py file (I used QtDesigner to do the layout) after importing the module where I save

Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio

帅比萌擦擦* 提交于 2019-12-17 05:41:15
问题 I use a QLabel to display the content of a bigger, dynamically changing QPixmap to the user. It would be nice to make this label smaller/larger depending on the space available. The screen size is not always as big as the QPixmap. How can I modify the QSizePolicy and sizeHint() of the QLabel to resize the QPixmap while keeping the aspect ratio of the original QPixmap? I can't modify sizeHint() of the QLabel, setting the minimumSize() to zero does not help. Setting hasScaledContents() on the

Segmentation fault when accessing the text of QLabel

倖福魔咒の 提交于 2019-12-13 10:24:32
问题 I got a problem with the QLabel. I got a QtWidget with a QLabel inside. Now I want to change the text of the Label with following code: QLabel* safetyLabel = this->findChild<QLabel *>("safety_bits"); safetyLabel->setText(QString("test")); printf("%i", (safetyLabel->text()).length()); but I always get a "Segmentation fault". I think it's something quite simple, but I just can't see it... Any ideas? 回答1: Your safetyLabel can be NULL if you use QtCreators' designer to build your UI and execute

Qt - Working with Threads

痴心易碎 提交于 2019-12-13 04:46:00
问题 I have a QTimer for executing OpenCV code and changing an image in a QLabel every 20 milliseconds, but I want to run this OpenCV code more naturally and not depend on the timer. Instead, I want to have one main thread that deals with user input and another thread that process images with OpenCV, what I can't find is a thread safe way to change the QLabel image (pixmap) in one thread from another thread, could someone describe this process, maybe give some code examples? I also want to know

Dynamic text size QLabel

吃可爱长大的小学妹 提交于 2019-12-13 02:33:52
问题 What is the best way to determine if text-size exceeds width of QLabel ? And according to that, change the text-size? I have a QLabel with word-wrap option set to true, but when text is so long it is being cropped from left and right side. 回答1: You might want to try this approach: QLabel label; QRect r = label.fontMetrics().boundingRect( "My text" ) ); int textWidth = r.width(); 来源: https://stackoverflow.com/questions/36331651/dynamic-text-size-qlabel

PyQt5 Image and QGridlayout

时光毁灭记忆、已成空白 提交于 2019-12-12 19:25:24
问题 I've a Widget, which wants to display Images with QLabel and QCheckBox . 4 classes are created each contains some information to be put on the final screen. Class Grid align and grid images, text and checkboxes. After script running get current screen. No images appear in present widget. Where are images? Desired screen The code import sys, os from PyQt5 import QtCore, QtGui, QtWidgets iconroot = os.path.dirname(__file__) class ImageWidget(QtWidgets.QWidget): def __init__(self, parent=None):

How do I make a circle QLabel?

拥有回忆 提交于 2019-12-12 16:18:30
问题 I have a QLabel that i fill in red with the stylesheet, but the QLabel is rectangular, and I want a circle. I try to add border-radius, but it doesn't work, maybe because i put my QLabel in a formLayout. Is there a simple method to have a round QLabel by using stylesheet ? Thanks. EDIT : Using a picture seems more easier than doing this now. 回答1: Create an image that you use as a mask and set that on the label by calling setMask. As the documentation states: - Causes only the pixels of the

How to make QLabel expand width geometry to accommodate text

≯℡__Kan透↙ 提交于 2019-12-12 06:47:36
问题 I currently have a QLabel that has some text in it. However when I put some text in it that exceeds its geometrical width then that extra text is not displayed. I do not want to enable wordwrap since I want the QLabel to expand horizontally. Is there anyway that Qlabel could increase its geometrical width based on its content. 回答1: Call QWidget::adjustSize() everytime you change the content of your label. I can't elaborate on other possible answers due to lack of information, but that will

Incorrect behaviour of scroll bars upon zooming an image in qt

不羁的心 提交于 2019-12-11 19:27:45
问题 I'm trying to implement zooming feature to my image-viewer-like appliction. I'm uploading an image like so: void MeasuresWidget::on_actionOpen_triggered() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()); if (!fileName.isEmpty()) { QImage image(fileName); if (image.isNull()) { QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName)); return; } ui->imageLabel->setPixmap(QPixmap::fromImage(image)); } scaleFactor = 1.0;