qgraphicsscene

How to use QPainter on QPixmap

余生颓废 提交于 2019-12-18 14:52:02
问题 I'm a newbie to Qt/Embedded. I want to use QPainter to draw stuff on a QPixmap , which will be added to QGraphicsScene . Here is my code. But it does not show the drawings on the pixmap. It shows only the black pixmap. int main(int argc, char **argv) { QApplication a(argc, argv); QMainWindow *win1 = new QMainWindow(); win1->resize(500,500); win1->show(); QGraphicsScene *scene = new QGraphicsScene(win1); QGraphicsView view(scene, win1); view.show(); view.resize(500,500); QPixmap *pix = new

How to resize QWidget added in QGraphicScene through QGraphicsProxy?

非 Y 不嫁゛ 提交于 2019-12-14 03:57:24
问题 I have added a widget to a graphic scene (QGraphicScene) through a QGraphicsProxyWidget. To move and select the widget added QGraphicsRectItem handle. To resize widget added QSizegrip to widget. But when i resize widget more than the QGraphicsRect item rect right and bottom edges goes behind .How to overcome this problem? When i resize widget graphics rect item should resize or vice-versa should happen. how to do this? Any other ideas are welcome. Here is the code auto *dial= new QDial(); //

Multicolor tooltip in Qt

让人想犯罪 __ 提交于 2019-12-14 03:52:05
问题 I want to have moveable multicolor tooltip for QGraphicsItems. For example when I click on graphicsItem in scene, tooltip appears, then during dragging mouse tooltip should follow cursor. I can implement movable tooltip with standard QToolTip, but seems Qt support only 1 color for whole tooltip. Also QToolTip doesn't have paintEvent, so I decide to create ColoredTooltip class inherited from QTextEdit, but problem appears when I show at first time ColoredTooltip object. It began to grab mouse

QGraphicsSceneMouseEvent get position will not work [duplicate]

大憨熊 提交于 2019-12-13 20:22:23
问题 This question already has an answer here : Qt Widgets and derived classes (1 answer) Closed 2 months ago . I am trying to make an application with a QGraphicsView in it. I tried to get the position of a mouse when the mouse was pressed with QGraphicsSceneMouseEvent, but it doesn't seem to work. The entire function is never called when I press the mouse. I would like to make an application that can load an image into the QGraphicsView and then when you press the mouse button, it should add a

How to show a QImage without copying in QGraphicsScene

两盒软妹~` 提交于 2019-12-13 05:58:26
问题 I have my own image class containing an unsigned char array with RGB values. I would like to show images stored in this class, without copying them, in a QGraphicsScene. I can make an QImage with QImage image(data, width, height, width * 3, QImage::Format_RGB888); without copying my image. How can I show image in a QGraphicsScene without a deep copy of data? 回答1: With the default, raster paint engine/backend, the top-level widget's contents are stored as a QImage . Drawing a QImage (and a

What is the meaning of “the item's view geometry and scene geometry will be maintained separately”?

好久不见. 提交于 2019-12-13 04:43:02
问题 The documentation for the QGraphicsItem::ItemIgnoresTransformations flag says The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item's view geometry and scene geometry will be maintained separately . You must call

Deleting a QGraphicsItem/QGraphicsObject from QGraphicsScene?

泪湿孤枕 提交于 2019-12-13 01:19:47
问题 I have created Qt GUI application. It consists of QGraphicsScene , and items ( QGraphicsItem s) are added to them by pressing or triggering pushbutton s. Each item added to the scene are members of different classes derived from QGraphicsItem . Now, my challenge is to delete an added item off the scene through one of the following mechanisms: 1) Right click an added item, create a context menu, and then use scene->removeItem(addedItem); 2) Double click the item which deletes the item 3)

QGraphicsView / QGraphicsScene size matching

被刻印的时光 ゝ 提交于 2019-12-12 13:31:44
问题 How do you make a QGraphicsScene with a specified size and a QGraphicsView to monitor that scene with the same size? This sounds like a stupid question but consider the following test code [1] import sys from PyQt4 import QtGui, QtCore class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.scene = QtGui.QGraphicsScene(0, 0, 200, 200, self) self.view = QtGui.QGraphicsView(self.scene, self) #self.view.setMaximumSize(200, 200) self.setCentralWidget(self

Qt: QGraphicsScene not updating when I would expect it to

我怕爱的太早我们不能终老 提交于 2019-12-12 09:54:33
问题 Ok so I've got a QGraphicsScene in a class called eye. I call a function: void eye::playSequence(int sequenceNum) { for (int i=0; i<sequences[sequenceNum].numberOfSlides(); i++) { presentSlide(sequenceNum, i); time_t start; time(&start); bool cont=false; while (!cont) { time_t now; time(&now); double dif; dif=difftime(now, start); if (dif>5.0) cont=true; } } } which for each slide calls: void eye::presentSlide(int sequenceNum, int slideNum) { Slide * slide=sequences[sequenceNum].getSlide

Getting started with a Tile-based game in Qt using QGraphicsScene and QGraphicsView

拜拜、爱过 提交于 2019-12-12 07:57:10
问题 I'm going to start programming a 2D tile-based game in Qt and read about the QGraphicsScene and QGraphicsView classes which are intended for displaying and handling lots of 2D objects. My question is that will it be feasible to create a world with lots of tiles using QGraphicsScene? Can I add the whole world at once tile-by-tile or should I try to implement something to restrict the area a bit? I've read that QGraphicsScene can handle "thousands of items" but a 2D tile map can easily get