qgraphicsview

QGraphicsView scrolling and image scaling/cropping

萝らか妹 提交于 2019-12-06 03:06:21
问题 I would like to have a background image in my QGraphicsView that is always scaled (and cropped if necessary) to the size of the viewport, without scrollbars and without scrolling with the keyboard and mouse. The example below is what I am doing to scale and crop an image in the viewport, but I am using random values for the cropping that are pulled out of the aether. I would like a logical solution? MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui-

restrict movable area of qgraphicsitem

瘦欲@ 提交于 2019-12-06 02:49:12
问题 Is there a way to restrict the area where a QGraphicsItem like QRect can be moved when setFlag(ItemIsMovable) is set? I'm new to pyqt and trying to find a way to move an item with the mouse, and the restrict it to only vertically/horizontally. 回答1: If you want to keep a limited area you can reimplement the ItemChanged() Declare: #ifndef GRAPHIC_H #define GRAPHIC_H #include <QGraphicsRectItem> class Graphic : public QGraphicsRectItem { public: Graphic(const QRectF & rect, QGraphicsItem *

QGraphicsView: Disable automatic scrolling

依然范特西╮ 提交于 2019-12-06 00:30:21
问题 I want to have a QGraphicsView that never scrolls automatically. Similar: Basically, my question is identical to http://developer.qt.nokia.com/forums/viewthread/2220 , but that thread didn't receive an answer. What I have tried so far: Within showEvent() and resizeEvent(), I do ui->graphicsView->fitInView(...), which works fine as long as items do not overshoot the screen-rectangle I've also tried manipulating the view transform, but apart from scaling it's coefficients never change, so this

Qt update() doesn't work

ⅰ亾dé卋堺 提交于 2019-12-06 00:17:55
I have a problem , that update() function in QGraphicsItem doesn't work. What I want to do is , when I move circle , other QGraphicsItem ( in the mean time roundrect ) changes color. This is a example, what I want to do: circle.cpp: void CircleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { // RoundRect Object RectItem->SetBackGround(); QGraphicsItem::mouseMoveEvent( event ); } RoundRect.cpp: void RoundRectItem::SetBackGround() { ChangeBackground = true; update(); } void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QRectF rec =

Tracking mouse move in QGraphicsScene class

不打扰是莪最后的温柔 提交于 2019-12-05 10:06:24
问题 I subclassed QGraphicsScene and added method mouseMoveEvent to handle mouse move event. I created a ruler on top of GraphicsView and have the ruler tracking mouse movement. In the QGraphicsScene::mousemoveEvent I calls mouseMoveEvent of the ruler widget explcitely. The purpose is to have the ruler knows that the current mouse position. Now it seems that QGraphicsScene::mousemoveEvent is not called when I move the mouse. However, I can get it to work if I press the left mouse button and move

How to make qt qgraphicsview scale to not affect stipple pattern?

梦想的初衷 提交于 2019-12-05 06:01:30
I draw few rectangles inside the QGraphicsView ; I use custom stipple pattern for these by creating a QBrush with my QPixmap . This gets displayed with the default zoom level as expected. When I call view->scale() , the rectangles show up bigger or smaller as I expected. However Qt has scaled the individual bits of the stipple pattern which is not expected; I expected it to draw the larger or smaller rectangle again with the brush. Eg. If I had used a stipple pattern with one pixel dot and pixel space, after zooming in, I want to see a larger rectangle but I want the same stipple pattern with

Qt - drag and drop with graphics view framework

我们两清 提交于 2019-12-04 21:21:39
I'm trying to make a simple draggable item using the graphics framework. Here's the code for what I did so far: Widget class: class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); }; Widget::Widget(QWidget *parent) : QWidget(parent) { DragScene *scene = new DragScene(); DragView *view = new DragView(); QHBoxLayout *layout = new QHBoxLayout(); DragItem *item = new DragItem(); view->setAcceptDrops(true); scene->addItem(item); view->setScene(scene); layout->addWidget(view); this->setLayout(layout); } Widget::~Widget() { } DragView class: class DragView : public

QGraphicsScene is missing a particular item update

随声附和 提交于 2019-12-04 11:34:42
I've got an application where you can watch replays for a given 2D game : Basically, a vehicle is moving on a map. The view is centered on vehicle so the map is scrolling as replay is playing, something Micro Machines -like (it's just to give an idea, the actual game is not Micro Machines ). (source: randomracket.com ) In my scene, the map is static while the vehicle is moving around. The view is scrolling for each frame of the replay, so that vehicle is centered. For performance reason, the map is tiled in several QGraphicsPixmapItem s. Viewport update mode is set to QGraphicsView:

QGraphicsScene scaled weirdly in QGraphicsView

六月ゝ 毕业季﹏ 提交于 2019-12-04 11:13:33
I'm messing around with QGraphicsView and QGraphicsScene to create a Tic Tac Toe clone. I add some QGraphicsLineItem s to my scene and override the resizeEvent method of the Widget that contains the view, so that when the window is resized, the view and its contents are scaled appropriately. This works fine, except for the first time that I run the program: Once I resize the window by any amount, the scene is scaled correctly: Here's the code: main.cpp: #include <QtGui> #include "TestApp.h" int main(int argv, char **args) { QApplication app(argv, args); TestApp window; window.show(); return

Text in a QGraphicsScene

牧云@^-^@ 提交于 2019-12-04 11:04:24
How to write text in a certain cordinate in QGraphicsScene? I was trying to do like this, but with no success. Text has blck borders but inside the letters it is white, and I can't make it be black. QPainterPath path; QFont font; font.setPixelSize(50); path.addText(100, 50, font, tr("Hello World!!!")); path.setFillRule(); m_graphScen->addPath(path); Variant 1 (not a good one): QFont font; font.setPixelSize(10); font.setBold(false); font.setFamily("Calibri"); path.addText(100, 50, font, "Hello World!!"); m_graphScen->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black)); Variant 2 (fine