qwidget

Dragging a QWidget in QT 5

谁说我不能喝 提交于 2019-12-23 09:23:11
问题 I have to make something like the iOS interface, 3x3 field of icons that can be dragged to change their position, and then remember it in an XML file. I decided to use Grid class (QWidget is parent) as a container and my own class, inherited from QWidget, as elements. Now I'm trying to learn how to perform a drag & drop for QWidget, but it seems like you are only able to drop onto a QWidget, but it's impossible to drag it. Is it impossible? How do I move this thing? 回答1: Dragging a widget isn

QWidget doesn't close when main window is closed

青春壹個敷衍的年華 提交于 2019-12-23 08:28:32
问题 I'm trying to make a main window (QWidget) which open a new QWidget when a button is clicked but when I close the main window, the QWidget recently opened doesn't close. main.cpp QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); mainwindow.cpp (parent) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } out.cpp (child) Out::Out(QWidget *parent) : QWidget(parent), ui(new Ui::Out) { ui->setupUi(this); } 回答1: I suspect

QWidget doesn't close when main window is closed

空扰寡人 提交于 2019-12-23 08:28:08
问题 I'm trying to make a main window (QWidget) which open a new QWidget when a button is clicked but when I close the main window, the QWidget recently opened doesn't close. main.cpp QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); mainwindow.cpp (parent) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } out.cpp (child) Out::Out(QWidget *parent) : QWidget(parent), ui(new Ui::Out) { ui->setupUi(this); } 回答1: I suspect

How can I print a QWidget in Qt?

假如想象 提交于 2019-12-22 11:17:36
问题 I need to know how to print a QWidget as a PDF file. The Widget (QDialog) contains a lot of labels, some QPlainTextEdit and a background image. The Dialog shows a receipt with all of its field already filled. I already tried using QTextDocument and html for this purpose, but the complexity of the receipt(lots of image and format customisation) makes the html output completely messed up. This is the document. Receipt image 回答1: You have to use QPrinter and this is the object that you must use

Trouble loading Qt UI (with images) from plugin (.so)

风格不统一 提交于 2019-12-22 10:35:18
问题 I have a plugin that loads and shows a custom widget that displays an image (as a background for a QLabel) loaded from a resource file (resources.qrc). The problem I'm facing is that once the plugin is loaded, it shows the widget properly, but not the image. I tried putting "Q_INIT_RESOURCE( resources )" everywhere, but nothing happens. I have created many custom widgets that use qrc files to display images, but only directly within an app, which have worked just fine. This time is from a

QWidget how to receive keyPressEvent inside child widgets

痞子三分冷 提交于 2019-12-21 17:36:09
问题 I have one main Widget and inside this main widget I have QListWidget and two buttons. I have override the keyPressEvent inside the main widget (inherited from QWidget ). I can receive the keyPress events when focus is not on QListWidget , but when focus is inside the QListWidget I am unable to receive these keyPress events. Below is the code I have used to achieve this: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this-

Qt - QWidget: Cannot create a QWidget when no GUI is being used

隐身守侯 提交于 2019-12-21 03:42:39
问题 I'm trying to run a simple Qt program, and when doing so, I get a console window mentioning: QWidget: Cannot create a QWidget when no GUI is being used , and the second line This application has requested the Runtime to terminate..... , and the .exe file thus stops working. My .pro file looks as follows: #------------------------------------------------- # # Project created by QtCreator 2011-04-02T07:38:50 # #------------------------------------------------- QT += core QT += gui TARGET =

QPainter::drawPixmap() doesn't look good and has low quality?

妖精的绣舞 提交于 2019-12-21 02:30:28
问题 I'm trying to draw an icon(.png) inside a QWidget with QPainter::drawPixmap() : QPixmap _source = "/.../.png"; painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.drawPixmap(rect(), _source); but in comparing to QLabel (for example) and in lower size (19*19 in my case) the result isn't perfect. What can I do? ****Edit**** QLabel with pixmap @ size 19*19: My painting @ size 19*19 via SmoothPixmapTransform render type: 回答1: You are setting the wrong render hint, you need QPainter:

How to create screenshot of QWidget?

别说谁变了你拦得住时间么 提交于 2019-12-20 19:41:35
问题 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. 回答1: You can use QWidget::render for this. Assuming rectangle is a QRect: QPixmap pixmap(rectangle->size()); widget->render(&pixmap, QPoint(), QRegion(rectangle)); 回答2: From QWidget::Grab: QPixmap QWidget::grab(const

Save the screenshot of a widget

最后都变了- 提交于 2019-12-20 07:17:10
问题 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? 回答1