qt4

Get raw data from QImage

佐手、 提交于 2019-12-19 08:30:41
问题 I have a QImage that I built from a pixmap something like the following: QPixmap fullPmap = topItem->pixmap(); fullPmap = fullPmap.copy(isec.toRect()); QImage chip = fullPmap.toImage(); This is basically intersecting with a rectangle on screen to crop the image to a chipped size. I now need to get the character array representing that data back from chip. How can I do this? I tried something like this: unsigned char * data = chip.bits(); And when I display "data" I get a completely distorted

Changing a single strings color within a QTextEdit

隐身守侯 提交于 2019-12-19 07:56:13
问题 I am working on a GUI developed via PyQt and Qt4. Within my GUI I have a QTextEdit that has various data written to. Is there a way in which I can manipulate the color of one word within the QTextEdit? For example redText = "I want this text red" self.myTextEdit.write(redText) blackText = "And this text black" self.myTextEdit.append(blackText) Is this possible? If so, how could I do this? Regards, sudo!! 回答1: You should provide a rich text for it. It can be done by creating a <span> tag and

Qt Signals/Slots and Threads

瘦欲@ 提交于 2019-12-19 07:38:08
问题 I'm new to GUI programming and multithreading. I am in the process of creating a real-time app that receives information from my car and renders it in some meaningful way. My app is layed out as 3 threads, the GUI (main thread), the rendering thread and the hardware comm thread. Inbetwen the the render and the hardware threads is a shared ring buffer. In the render I have created a timer so that it draws the new interface 20 times a second. I would like the thread to notify the main thread

Why does Qt change behaviour of sscanf()?

狂风中的少年 提交于 2019-12-19 05:21:19
问题 I have noticed, Qt (4.8) changes the behaviour of sscanf() . Without Qt sscanf() works as usual, but with, it takes only localized strings. Here's a minimized example: Without Qt (plain C++) int main(int argc, char *argv[]) { float f; sscanf("0.83", "%f", &f); std::cout << f << "\t-->\t" << typeid("0.83").name() << std::endl; return 0; } Output: 0.83 --> A5_c (given string is a 5x char -array, result correct) With Qt int main(int argc, char *argv[]) { /* * This breaks sscanf() for the whole (

Qt Application segmentation fault with MinGW 4.7.2

时光怂恿深爱的人放手 提交于 2019-12-19 03:37:20
问题 Using MinGW 4.7.2 every compiled Qt 4 application crashes - even programs that ran before. MinGW: 4.7.2 QT: 4.8.3 Used Libs: QtCore4.dll QtCored4.dll QtGui4.dll (used if gui) QtGuid4.dll (used if gui) Simple Program as an example: #include <QtGui/QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); /* Crash here */ return app.exec(); } Crash: Signal received: SIGSEGV (Segmentation fault) Call Stack: ZN23QCoreApplicationPrivate27processCommandLineArgumentsEv+68: mov (

Qt, VS2005, Qwt - Can't use Q_OBJECT in class derived from Qwt widgets

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 03:20:46
问题 We've compiled QT 4.6 and QWT 5.2.0 for VS2005. We're trying to derive a class from QwtDial, and the derived class has slots. So, we need to add the Q_OBJECT macro. However, when we do that, the linker chokes out this error: error LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtDial::staticMetaObject" (?staticMetaObject@QwtDial@@2UQMetaObject@@B) I've looked at the Qwt.dll with depends, and it has that function. Looking at the .lib file with a hex editor shows

Creating a QWidget in a non-GUI thread

房东的猫 提交于 2019-12-18 20:49:11
问题 Yes, I know that you cannot use GUI things from non-GUI threads. However, it seems reasonable to be able to create a QWidget object, send it to the GUI thread, and then send signals to it. However, when I try to do so, I get errors that widgets cannot be moved. However, this seems to works: #include <iostream> #include <QApplication> #include <QtConcurrentRun> #include <QDialog> class BasicViewer : public QDialog { Q_OBJECT public: void Function(const float a) { std::cout << a << std::endl; }

How to delete an already existing layout on a widget?

蹲街弑〆低调 提交于 2019-12-18 19:16:21
问题 You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout. from http://doc.qt.io/qt-5.9/qwidget.html#setLayout Which function is used for deleting the previous layout? 回答1: You just use delete layout; like you would with any other pointer you created using new . 回答2: Chris Wilson's answer is correct, but I've found the layout does not delete sublayouts and qwidgets beneath it. It's best to do it manually if you have

Qt4 + mplot3d of matplotlib

别来无恙 提交于 2019-12-18 17:32:04
问题 I am trying to embed a 3D plot in a Qt4 GUI (has other buttons), is this possible using matplotlib's mplot3d? I am aware that 2d plots are possible using "matplotlib.backends.backend_qt4agg", and i have done this. If yes, please quote an example. If no, what is the favorite option? VTK? Thanks! 回答1: While not the cleanest thing you're going to see. I've noticed that is it not as fast as the tkinter backend. Then again it works. Have fun: import os import sys from PyQt4 import QtCore, QtGui

To set widgets on children items on QTreeView

喜欢而已 提交于 2019-12-18 17:28:19
问题 Thanks to this thread, I'm able to add widgets to 2nd or later column of QAbstractItemView (in my example QTreeView) of top level items of a view . But is it possible to add widgets to the children items? Here's what I've tried which partly went well: #!/usr/bin/env python import os from PyQt4.QtCore import QModelIndex, Qt from PyQt4.QtGui import QApplication, QItemSelectionModel, \ QPushButton, QStandardItem, \ QStandardItemModel, QTreeView from PyQt4.uic import loadUi class PrvTreeviewNest