c
cordsac18. Oktober 2017 13:03

How can I select the QGraphicView Item and change the properties

qt, c++

How can I select the QGraphicView items using mouse and change the properties(size,color).In this code I create Rectangles when the button clicks.But now I need to change properties of the rectangles.How can I select the each rectangle shapes using mouse and change the properties of the each one.


void Widget::on_btnCreateRect_clicked()
{

    QBrush blueBrush(Qt::green);
    QPen blackPen(Qt::black);
    blackPen.setWidth(2);

    rect = ui->graphicsView->scene()->addRect(-10,-10,250,100,blackPen);
    rect->setFlag(QGraphicsItem::ItemIsMovable, true);
}

http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html In this example it can select square shapes and change the color of each squares.I need to do same thing and change the size of each shape,but I have no idea to do it.how can I do it?
Рекомендуємо хостинг TIMEWEB
Рекомендуємо хостинг TIMEWEB
Stabiles Hosting des sozialen Netzwerks EVILEG. Wir empfehlen VDS-Hosting für Django-Projekte.

Magst du es? In sozialen Netzwerken teilen!

8
Evgenii Legotckoi
  • 19. Oktober 2017 03:34
  • (bearbeitet)

It is very big question.
First I give You idea, from that You can start, but some example I can write to you on weekend only.


Therefore, first, try to make changing of color.
For example, You need to make your own class from QGraphicsItem, or QGraphicsRectItem.
Example in this article . In this article You will find example of moving items on QGraphicsScene without flag ItemIsMovable. You need just to change logic to changing of color instead of moving the item.
    c
    • 19. Oktober 2017 05:49

    Ok I'll check it sir,If you can please do article(tutorial) about this,Its really useful.Thank you
    if you can give me some sample code when you free.thanks again

      Evgenii Legotckoi
      • 22. Oktober 2017 05:05

      I found my old project, where I made simple Vector Editor. I wrote article about this editor and you will find link to project.
      You can research it. In this project You will see, why I said your question is very big.


        Evgenii Legotckoi
        • 22. Oktober 2017 07:40
        • Die Antwort wurde als Lösung markiert.

        And It will be very cool, if have oportunities to share this article in some socials networks. Thanks.

          c
          • 22. Oktober 2017 12:52

          Thank you very much sir,My next problem was how re - size the QGraphicViewItem (such as rectangle) using mouse,I think your project also have that function,thanks again :)

            c
            • 22. Oktober 2017 15:27
            • (bearbeitet)

            You are correct sir, this is a big question,most part of your solution I can't understand.If you can please explain your project sir.If you can  please explain your code with each classes or please make some video tutorial with basic example,thank you

            https://evileg.com/post/291/

              Evgenii Legotckoi
              • 23. Oktober 2017 03:49
              I can to explain project, but I haven`t time to make video tutorial.
              Just ask a new questions on forum about moments, which you don't understand. And I will explain you it step by step.
                c
                • 23. Oktober 2017 13:18

                I posted it here sir

                  Kommentare

                  Nur autorisierte Benutzer können Kommentare posten.
                  Bitte Anmelden oder Registrieren
                  Letzte Kommentare
                  A
                  ALO1ZE19. Oktober 2024 08:19
                  Fb3-Dateileser auf Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
                  ИМ
                  Игорь Максимов5. Oktober 2024 07:51
                  Django – Lektion 064. So schreiben Sie eine Python-Markdown-Erweiterung Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
                  d
                  dblas55. Juli 2024 11:02
                  QML - Lektion 016. SQLite-Datenbank und das Arbeiten damit in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
                  k
                  kmssr8. Februar 2024 18:43
                  Qt Linux - Lektion 001. Autorun Qt-Anwendung unter Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
                  Qt WinAPI - Lektion 007. Arbeiten mit ICMP-Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
                  Jetzt im Forum diskutieren
                  J
                  JacobFib17. Oktober 2024 03:27
                  добавить qlineseries в функции Пользователь может получить любые разъяснения по интересующим вопросам, касающимся обработки его персональных данных, обратившись к Оператору с помощью электронной почты https://topdecorpro.ru…
                  JW
                  Jhon Wick1. Oktober 2024 15:52
                  Indian Food Restaurant In Columbus OH| Layla’s Kitchen Indian Restaurant If you're looking for a truly authentic https://www.laylaskitchenrestaurantohio.com/ , Layla’s Kitchen Indian Restaurant is your go-to destination. Located at 6152 Cleveland Ave, Colu…
                  КГ
                  Кирилл Гусарев27. September 2024 09:09
                  Не запускается программа на Qt: точка входа в процедуру не найдена в библиотеке DLL Написал программу на C++ Qt в Qt Creator, сбилдил Release с помощью MinGW 64-bit, бинарнику напихал dll-ки с помощью windeployqt.exe. При попытке запуска моей сбилженной программы выдаёт три оши…
                  F
                  Fynjy22. Juli 2024 04:15
                  при создании qml проекта Kits есть но недоступны для выбора Поставил Qt Creator 11.0.2. Qt 6.4.3 При создании проекта Qml не могу выбрать Kits, они все недоступны, хотя настроены и при создании обычного Qt Widget приложения их можно выбрать. В чем может …

                  Folgen Sie uns in sozialen Netzwerken