qwidget

Drawing points on QPixmap on QWidget (pyqt5)

折月煮酒 提交于 2019-12-01 11:23:29
I have a QWidget with a QLayout on which there is a QLabel. I set a QPixmap on the label. Wherever the user clicks on the image, I want to draw a point. I defined mouseReleaseEvent (which works) and paintEvent (but no points are drawn). I've read all similar questions and none of the solutions worked for me. Any help? My relevant code: class ImageScroller(QtWidgets.QWidget): def __init__(self, img): QtWidgets.QWidget.__init__(self) main_layout = QtWidgets.QVBoxLayout() self._image_label = QtWidgets.QLabel() self._set_image(img) main_layout.addWidget(self._image_label) main_layout.addStretch()

Rendering QWidget to QImage loses alpha-channel

我怕爱的太早我们不能终老 提交于 2019-12-01 06:54:58
问题 I have a simple Qt widget. It's a QLabel with a simple CSS style applied. The important part of the style is a round border: QString css("border-style: solid;" "border-width: 3px;" "border-radius: 7px;"); It is displayed on screen fine. The corners of the label beyond the border are filled with transparent color, so it looks great on any background. Here's how it looks when displayed over another widget (which has dark grey background color): Now, when I render it to QImage like so QImage

How to remove QWidgets from QSplitter

拟墨画扇 提交于 2019-12-01 03:15:36
In my app have a window splitted by a QSplitter, and I need to remove an widget. How can I do that? I can't find useful methods Tuminoid Many things in Qt cannot be "traditionally" removed. Instead call hide() on it and destruct it. From QSplitter documentation: When you hide() a child its space will be distributed among the other children. It will be reinstated when you show() it again. It's not clear to me if you want to preserve the widget and put it somewhere else, or if you want to destroy the widget. Destroying the widget: If you can get a pointer to the widget, you can simply delete it.

Programmatically promote QWidget

佐手、 提交于 2019-11-30 22:50:56
I have an ui file with a QProgressBar in a QWidget . Moreover, I've created my custom progress bar component that inherits from QProgressBar . In QT Designer, I can promote the QProgressBar widget to my custom widget. Is there a way to do this in the widget cpp file instead of using QT Designer? In other words, is there a way to programmatically promote a QWidget into an another custom widget of the same type (a sort of morphing )? Here follows an example: class MyProgressBar : public QProgressBar { Q_OBJECT public: explicit CmdProgressWidget(QWidget *parent = 0); ~CmdProgressWidget(); int

How does one fill a QGridLayout from top-left to right?

百般思念 提交于 2019-11-30 21:02:19
I would like to fill a QGridLayout with QWidgets . The QWidgets need to appear in a top-left to top-right fashion and proceed to fill the down downwards after each row is filled with QWidgets . An example of a similar and familiar GUI is how Apple sorts its apps on the iPhone or iPad's home screen. The apps go top-left to top-right and proceed to go downward after each row is filled. Right now, whenever I add elements, they take up the entirety of the screen and/or aren't added next to each other. This is example code of what I am doing m_gridLayout = new QGridLayout(this); this->setLayout(m

Qt4: Placing QMainWindow instance inside other QWidget/QMainWindow

扶醉桌前 提交于 2019-11-30 20:35:23
I'd like to place QMainWindow instance inside another QWidget (for example centralWidget of another QMainWindow). I'm wondering why it doesn't work ? QMainWindow inherits directly from QWidget. Placeing QWidget inside another QWidget works fine. I often place QMainWindow instances in QTabBar without any problems. ps You may ask why do I need to use QMainWindow ? I want to place 2 widgets inside 1 form using vertical layout. I want both widgets to have seperate Toolbars directly over them. Maybe there is some other way to place toolbars inside plain QWidgets using QtCreator ? Edit First example

Qt4: Placing QMainWindow instance inside other QWidget/QMainWindow

半世苍凉 提交于 2019-11-30 17:00:26
问题 I'd like to place QMainWindow instance inside another QWidget (for example centralWidget of another QMainWindow). I'm wondering why it doesn't work ? QMainWindow inherits directly from QWidget. Placeing QWidget inside another QWidget works fine. I often place QMainWindow instances in QTabBar without any problems. ps You may ask why do I need to use QMainWindow ? I want to place 2 widgets inside 1 form using vertical layout. I want both widgets to have seperate Toolbars directly over them.

Qt: shadow around window

泪湿孤枕 提交于 2019-11-30 13:48:12
I can add shadow to widget: QGraphicsDropShadowEffect *bodyShadow = new QGraphicsDropShadowEffect; bodyShadow->setBlurRadius(9.0); bodyShadow->setColor(QColor(0, 0, 0, 160)); bodyShadow->setOffset(4.0); ui->widget->setGraphicsEffect(bodyShadow); But this shadow will be only at left and down. I need shadow around widget. How to add this? You can create your custom effect. I'll share an implementation that works. customshadoweffect.h #ifndef CUSTOMSHADOWEFFECT_H #define CUSTOMSHADOWEFFECT_H #include <QGraphicsDropShadowEffect> #include <QGraphicsEffect> class CustomShadowEffect : public

Resizing qt widgets when their children are hidden

孤街醉人 提交于 2019-11-30 11:42:07
How would I go about resizing the widget when the retry child is hidden so that it looks as in the first image? The main layout is a QVBoxLayout, the retry child is a widget with a QVBoxLayout as well. I've tried the following: update() updateGeometry() setGeometry(childrenRect()) layout()->activate() on the main widget as soon as I've set the retry widget to hidden. Do I need to intercept some event to do this? Patrice Bernassola The adjustSize function may do what you want. Here is a basic example which does auto-resize upon widget hide/show. dialog.h file: #ifndef DIALOG_H #define DIALOG_H

What Qt widget(s) to use for read-only, scrollable, collapsible, icon list

試著忘記壹切 提交于 2019-11-30 08:32:54
I'm relatively new to Qt, and am not entirely familiar with the out-of-the-box widgets. I have a somewhat (but not very) complex widget to create, and don't want to reinvent any wheels. What is the best QWidget to use as a starting point to subclass and/or QWidgets to use to compose my widget. Here is the end-result I am looking for (apologies for the crude drawing): Key points: All icons will take up the same size, say 128 x 128. Ignoring the category groupings, they should all align in a nice grid. The widget should expand to fill all the horizontal and vertical area it can take. Expanding /