qgraphicsview

How can I change QGraphicsView background using check box

╄→гoц情女王★ 提交于 2019-12-10 21:04:54
问题 In this code,which change the QGraphicsView background.Now I need to change the background when I check true checkBox .When I set to checkBox to check true I need to set the background like this code.When I set checkBox to check false . I need to set QGraphicsView for normal default way. How can I do this. here is my code: mainwindow.cpp #include "mainwindow.h" #include <QGraphicsTextItem> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { scene = new Scene(this); scene-

Getting the size of a QGraphicsView

谁都会走 提交于 2019-12-10 20:29:38
问题 I want to know the size of a certain QGraphicsView . Its size isn't fixed because the widget is part of a grid layout. I tried using this->ui->myGraphicsView->width() and its height equivalent but these values aren't accurate. How can I get the current size of a QGraphicsView ? 回答1: Constantly received 100x30 as the size of my QGraphicsView as well. It turned out I was asking for the size of the QGraphicsView before it was shown. After moving my initialization code to showEvent, I got the

How to reset the scale in QGraphicsView?

北城余情 提交于 2019-12-10 18:09:53
问题 How can I reset the scale of a Graphics View regardless of any previous scale that was applied? Using scale() multiplies the scale I give it to the previous one: ui->graphicsView->scale(0.1, 0.1); ui->graphicsView->scale(2, 2); // the scale factor is (0.2,0.2), NOT (2,2) This is not what I want, I want to just set the scale to (2,2). 回答1: I looked into the sources and scale() uses a matrix internally: void QGraphicsView::scale(qreal sx, qreal sy) { Q_D(QGraphicsView); QTransform matrix = d-

Qt QGraphicsView unit testing - how to keep the mouse in a “pressed” state?

爱⌒轻易说出口 提交于 2019-12-10 13:25:32
问题 I have a fairly complex QGraphicsView/Scene setup where by I have items with complex interactions. As such I want to unit test this to avoid creating bugs in already existing functionality. For one test I wish to: Press the mouse down on an item in the scene Move the mouse to the right Release the mouse This will allow me to check that the item was selected, was moved by the correct amount, and was deselected. However I find that after sending mouseMove events the mouse state becomes

In ScrollHandDrag mode of QGraphicsView, How to stop movement of QGraphicsItems on scene?

无人久伴 提交于 2019-12-10 12:58:53
问题 I have multiple QGraphicsItem s in scene spread across different parts of scene. In application there are different modes in one of mode user can scroll the scene (palm drag mode). To achieve scrolling over scene I set dragMode of QGraphicsView to ScrollHandDrag . But the problem is when user try to scroll over scene by dragging ( MousePress and MouseMove ) on any of QGraphicsItem instead of scrolling scene it moves QGraphicsItem . How can I stop movement of QGraphicsItem and scroll the scene

Accepting drops on a QGraphicsScene

人盡茶涼 提交于 2019-12-10 12:56:18
问题 I'm trying to implement drag'n'drop for a QGraphicsScene . Here are the events I've overloaded: void TargetScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event) { bool acceptDrag = false; const QMimeData* mime = event->mimeData(); // Is an image present? if (mime->hasImage()) { QImage img = qvariant_cast<QImage>(mime->imageData()); dragPix = QPixmap::fromImage(img); acceptDrag = !dragPix.isNull(); } event->setAccepted(acceptDrag); } void TargetScene::dropEvent(QGraphicsSceneDragDropEvent

How to erase a QGraphicsItem from QGraphicsView using QPushButton

旧城冷巷雨未停 提交于 2019-12-10 11:58:49
问题 I am building a major user interface but I am stuck on a problem and in order to shrink the problem I build a small working example that carries exactly the problem. After the user creates a new .db file using the icon and saving for example to Desktop it is possible to load images(only in .png format for now) in the QGraphicsView and cliking on the checkbox to enable from Right: Drag to Right:Select it is possible to draw boxes on the image. With a right click inside the drawn box we can

Interactively editing an existing rectangle on a QPixmap?

十年热恋 提交于 2019-12-09 08:04:18
I'm trying to creat a Dicom GUI Toolkit where the user selects some dicom images and the image of first dicom image from the selected ones will be shown. Then the user clicks on the image and the image pops out with bigger image window. In this shown bigger image, the image will consist of a red colored rectangle that contains necessary regions of the Dicom image while the unnecessary region is outside the rectangle. The user should then have the option to change the rectangle by mouse. Until now, I have been able to show the big dicom image with the rectangle in it using QLabel which is by

QWheelEvent not working when using N.2 QGraphicsView in the same UI

时光毁灭记忆、已成空白 提交于 2019-12-09 04:21:28
I am building a user interface that has N.2 QGraphicsView and I am only able to zoom in-out on one QGraphicsView. I am using QWheelEvent + CTRL for one QGraphicsView and QWheelEvent + ALT for the second QGraphicsView. I read very useful articles to develop this procedure such as this and this but all of them are for zooming in-out for only one QGraphicsView. So sorry for writing with this problem again but I have been struggling a lot in the past days since I am trying to do it for two different QGraphicsView.. I am including a snippet of the code (mostly I used code from this post ) to do the

Changing the cursor in a QGraphicsView

瘦欲@ 提交于 2019-12-08 16:41:28
问题 I'm trying to change the cursor of a QGraphicsView while the ScrollHandDrag is on, but it doesn't seem to work. I can change the cursor if I disable the ScrollHandDrag but not while it's active, I don't see what I could possibly be doing wrong... Bellow is a portion of code that reproduce the problem: QApplication app(argc, argv); QGraphicsScene scene; QRect rectangle(-8, -4, 100, 100); QPen pen(Qt::blue, 1, Qt::SolidLine); scene.addRect(rectangle, pen); scene.setBackgroundBrush(Qt::white);