qwidget

Qt: what layout or combination of layout should use in this case?

 ̄綄美尐妖づ 提交于 2019-12-03 16:22:44
I am working on a Qt Project and for this project I require to design something like this: I have designed so far in Qt Creator and I have the component ready, but when I am trying to add widget in different layouts, I am not getting the shapes I want. What should I do to make my application resizable? Catches: Sidebar has fixed width, which means for horizontal increment of window size the sidebar's horizontal width won't increase. Sidebar itself is a widget. upperbar's vertical width is fixed (if possible). Which means, during vertical window size increment the upperbar can't become

Is there a way to add a QWidget to a QMenu in QtCreator

こ雲淡風輕ζ 提交于 2019-12-03 12:06:55
I'm creating a text editor and I'd like to put the QComboBox in the QMenu . I didn't find any method inside the QMenu that handled such a thing. The closest is QMenu::addAction() . I was wondering of getting around this hurdle. Thanks! pnezis You have to subclass QWidgetAction and then simply call the addAction to your menu. Example code for Spin Box Action with a label class SpinBoxAction : public QWidgetAction { public: SpinBoxAction (const QString& title) : QWidgetAction (NULL) { QWidget* pWidget = new QWidget (NULL); QHBoxLayout* pLayout = new QHBoxLayout(); QLabel* pLabel = new QLabel

How to create screenshot of QWidget?

允我心安 提交于 2019-12-03 06:33:26
I work at my homework in Qt Creator, where I paint to QWidget and I need to save some part of this QWdiget. I tried to solve this problem: QPixmap pixmap; pixmap.copy(rectangle); // rectangle is part of QWidget, which I need to save pixmap.save("example.png"); Thank you for help. You can use QWidget::render for this. Assuming rectangle is a QRect: QPixmap pixmap(rectangle->size()); widget->render(&pixmap, QPoint(), QRegion(rectangle)); Very easy: QPixmap QWidget::grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1))) s.a.: http://doc.qt.io/qt-5/qwidget.html#grab 来源: https:/

PyQt5 - in a QMainMenu, how to make a QWidget the parent (temporarily)?

坚强是说给别人听的谎言 提交于 2019-12-02 20:17:46
问题 I have a QMainWindow that I initialize with a QWidget . I want that each Time I'll press the button New In my QMainWiindow , it will open the QWidget temporarily (in my case, until mouse button release). I'm having trouble interacting QMainWindow with the QWidget . I tried many options, but it seemed like everything I tried tied the QWidget to the QMainWindow screen, and I don't want that. It will be easier with an example: TempWidgetMenu.py is my QMainWindow class. When I press New , a

Save the screenshot of a widget

三世轮回 提交于 2019-12-02 12:47:45
I want to save a screenshot of a widget in Qt. I created the following code that should work: QWidget* activeWidget = getActiveWidget();//a function that returns the current widget. if (activeWidget == NULL) { return; } QPixmap screenshot; screenshot = QPixmap::grabWidget(activeWidget,activeWidget->rect()); if(screenshot.isNull()){ printf("ERROR"); } bool a= screenshot.save("c:\\temp\\asd.jpg", "JPG", 50); But unfortunately this does not seem to work. Does anyone know what the problem is? Tim Meyer In this answer and this forum post , people suggest the following: Most likely, the plugin which

PyQt5 - in a QMainMenu, how to make a QWidget the parent (temporarily)?

只愿长相守 提交于 2019-12-02 09:57:17
I have a QMainWindow that I initialize with a QWidget . I want that each Time I'll press the button New In my QMainWiindow , it will open the QWidget temporarily (in my case, until mouse button release). I'm having trouble interacting QMainWindow with the QWidget . I tried many options, but it seemed like everything I tried tied the QWidget to the QMainWindow screen, and I don't want that. It will be easier with an example: TempWidgetMenu.py is my QMainWindow class. When I press New , a QWidget will appear, it Will color the screen gray-ish, and will color a rectangle from a button press, to

Ignore minimum size when resizing QWidget

自闭症网瘾萝莉.ら 提交于 2019-12-02 08:22:48
Is there a way to make a QWidget (and any subclass of it) completely ignore its minimum size? What I want is for a QPushButton to cut off when it is sized too small, rather than prevent the window from resizing (the default behavior). You can use: button.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) but you'll have to set the initial size yourself. Or you can just set the minimum size to a small non-zero value: button.setMinimumSize(1,1) To apply that to all buttons within a widget, you could try to use a style sheet, but the borders don't disappear when the button is at its minimum

Unable to close the GUI application

我与影子孤独终老i 提交于 2019-12-02 04:51:10
问题 from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(277, 244) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22)) self.menubar.setObjectName("menubar") self.menuFile = QtWidgets.QMenu(self

Using an alpha transparent mask on a QWidget?

眉间皱痕 提交于 2019-12-02 03:41:19
问题 Is it possible to assign an alpha-transparent mask to a QWidget? I know how to set a mask using setMask but it seems it only supports black&white masks. Is it possible to make it support a true alpha channel? i.e. currently I have a PNG like this: and a widget like this: If I load my PNG in a QPixmap and set it as a mask, I get this (notice the edges): However I would like to get this (smooth edges): Any idea how to do that? Note: I'm doing some more complex drawing on the widget, which must

Unable to close the GUI application

荒凉一梦 提交于 2019-12-02 02:12:59
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(277, 244) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22)) self.menubar.setObjectName("menubar") self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile.setObjectName("menuFile") MainWindow.setMenuBar(self.menubar) self.actionQuit =