Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Erase tool
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Erase tool

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      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

      http://anavi.org/

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anticross
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          silver47
          wrote on last edited by
          #4

          @setCursor(QCursor)@

          sorry for my english :(

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anticross
            wrote on last edited by
            #5

            [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 ?

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              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.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • S Offline
                S Offline
                silver47
                wrote on last edited by
                #7

                If you create QCursor from pixmap, may be you can use .scale() method?

                sorry for my english :(

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Anticross
                  wrote on last edited by
                  #8

                  @// 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 ?

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    irtusb
                    wrote on last edited by
                    #9

                    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));
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Anticross
                      wrote on last edited by
                      #10

                      [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 ?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        silver47
                        wrote on last edited by
                        #11

                        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_OBJECT

                        QPushButton     *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.

                        sorry for my english :(

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Anticross
                          wrote on last edited by
                          #12

                          Yep, this helps. As I was thinking system cursor can;t be resized. silver47, thanks for the help and code example.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved