[SOLVED] Erase tool
-
I making something like a little graphical editor and need to add erase tool like in Photoshop or any other editor. So I need to erase pixels covered by my cursor, also I need Cursor which can change it's size by pressing "+" or "-" key. The problem is actually how to resize my cursor with holding it's current shape, and how to get pixels covered by my cursor ?
-
Hi,
I think you can create custom cursor using "QCursor":http://doc.qt.nokia.com/4.7/qcursor.html After that you should be able to "override application's cursor":http://doc.qt.nokia.com/4.7/qapplication.html#setOverrideCursor or just to "use it for a selected widget":http://doc.qt.nokia.com/4.7/qwidget.html#cursor-prop
Best regards,
Leon -
Ok. I've got some cursor and now I need to make it bigger. So 1-st step is to get current cursor - it's easy , 2-nd make it's size bigger(or smaller) I don't know how, 3-rd to apply new cursor for application(or current Widget) it's simple too. Can anyone give me any code samples ?
-
@setCursor(QCursor)@
-
[quote author="silver47" date="1306642716"]@setCursor(QCursor)@[/quote]
Yep, I know this :) it thats simple steps 1-st and 3-rd. But what about 2-nd step, any code samples ?
-
Just a simple idea :
since QCursor gets its size from the pixmap or bitmap, you could use several pixmap sizes stored on your system to solve step 2. I guess your current cursor is one you made yoursef? If so you could make the other sizes too. (1x1 pixel, 2x2, 3x3, ...)On kubuntu and debian (or more general on linux) I know these pixmaps are stored in separate directories.
hope this helps.
-
If you create QCursor from pixmap, may be you can use .scale() method?
-
@// Change cursor shape
QCursor cursor = Qt::ArrowCursor;
QPixmap cursorPix = cursor.pixmap();
cursorPix.scaled(QSize(300,300),Qt::IgnoreAspectRatio,Qt::FastTransformation);
cursor = QCursor(cursorPix);
setCursor(cursor);
@Following code has no effect. Any ideas ?
-
method "scaled()":http://doc.qt.nokia.com/4.7/qpixmap.html#scaled returns a scaled version of the original image, it does not alter the original.
you can try using@
cursor = QCursor(cursorPix.scaled(QSize(300,300),Qt::IgnoreAspectRatio,Qt::FastTransformation));
@ -
[quote author="Jota" date="1306722994"]method "scaled()":http://doc.qt.nokia.com/4.7/qpixmap.html#scaled returns a scaled version of the original image, it does not alter the original.
you can try using@
cursor = QCursor(cursorPix.scaled(QSize(300,300),Qt::IgnoreAspectRatio,Qt::FastTransformation));
@
[/quote]Same as before - no effect :( . The cursor stays in it's sizes. Maybe I need to try custom cursor not system ?
-
bq. Maybe I need to try custom cursor not system?.
I think You can't resize system cursor.
I try to make this and I have no problems.
widget.h
@#ifndef WIDGET_H
#define WIDGET_H#include <QtGui/QWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include <QCursor>class Widget : public QWidget
{
Q_OBJECTQPushButton *incrBtn; QPushButton *decrBtn; int curSize;
public:
Widget(QWidget *parent = 0);
~Widget();private slots:
void increaseCursor();
void decreaseCursor();
};#endif // WIDGET_H@
widget.cpp
@#include "widget.h"Widget::Widget(QWidget *parent) : QWidget(parent), curSize(5){
QHBoxLayout *mainLay = new QHBoxLayout(this);
mainLay->addWidget(incrBtn = new QPushButton("Increase Cursor"));
mainLay->addWidget(decrBtn = new QPushButton("Decrease Cursor"));
QObject::connect(incrBtn, SIGNAL(clicked()), this, SLOT(increaseCursor()));
QObject::connect(decrBtn, SIGNAL(clicked()), this, SLOT(decreaseCursor()));this->setLayout(mainLay); this->setFixedSize(400, 300); QPixmap pix(":/clock.png"); pix = pix.scaled(10 * curSize, 10 * curSize); QCursor cur(pix); this->setCursor(cur);
}
Widget::~Widget(){
}void Widget::increaseCursor(){
if(curSize > 9) return;++curSize; QPixmap pix(":/clock.png"); pix = pix.scaled(10 * curSize, 10 * curSize); QCursor cur(pix); this->setCursor(cur);
}
void Widget::decreaseCursor(){
if(curSize <= 1) return;--curSize; QPixmap pix(":/clock.png"); pix = pix.scaled(10 * curSize, 10 * curSize); QCursor cur(pix); this->setCursor(cur);
}
@I'm sorry if this is very big. I can't find how to add zip file.
-
Yep, this helps. As I was thinking system cursor can;t be resized. silver47, thanks for the help and code example.