Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Question about: QGraphicsView - Dynamic(with Slider) Change Color
QtWS25 Last Chance

Question about: QGraphicsView - Dynamic(with Slider) Change Color

Scheduled Pinned Locked Moved Qt Creator and other tools
6 Posts 2 Posters 5.5k Views
  • 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.
  • Q Offline
    Q Offline
    Q_Tim
    wrote on last edited by
    #1

    Hi somebody,

    I'm a freshman about Qt and have a question about the QGraphicsView, when I use qt creator with Designer.

    I want to use Slider(R, G, B), dynamic to change the Color of QGraphicsView.
    I found, that "setStyleSheet" was not practice.

    Someone can help me?

    Thanks!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What color do you want to change, exactly? A QGraphicsView itself is not very interesting, it only shows QGraphicsItems. Do you want to change the background color perhaps?

      You will need to be much clearer on your questions if you hope to receive an answer you can actually use...

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Q_Tim
        wrote on last edited by
        #3

        There are 3 Slider, which are R, G and B, to control the color.

        When I change the Slider, the color will be automatic changed.

        Maybe I need to add a RectItem in the QGraphicsView and then to let it show the color?

        @
        connect(ui->RRGB,SIGNAL(sliderMoved(int)),this,SLOT(RGB_RGBView()));
        connect(ui->GRGB,SIGNAL(sliderMoved(int)),this,SLOT(RGB_RGBView()));
        connect(ui->BRGB,SIGNAL(sliderMoved(int)),this,SLOT(RGB_RGBView()));
        @

        the function "RGB_RGBView()" is the controller - control the color.

        (Maybe to change the backgroud color of QGraphicsView is not advisable...)

        Thanks!

        [quote author="Andre" date="1320648499"]What color do you want to change, exactly? A QGraphicsView itself is not very interesting, it only shows QGraphicsItems. Do you want to change the background color perhaps?

        You will need to be much clearer on your questions if you hope to receive an answer you can actually use...[/quote]

        [EDIT: code formatting, please use @-tags, Volker]

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Q_Tim
          wrote on last edited by
          #4

          MODERATOR's note:
          Double content (same code snippet, but formatted) deleted.
          Please use the edit function to change or add to your posts and comments. The link is right to each post, just below the avatar and user name.
          Volker

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

            Well, you are the only one who knows of what you want to change the color. If that is the background color, then that is the background color. If it is the color of an item on the view, then do that.

            If you want to change the background color, you could do something like this:
            @
            //in your header

            Q_OBJECT // do not forget this one in the private section of your class declaration

            private slots:
            void RGB_RGBView();

            //in your implementation file:
            void MyClass::RGB_RGBView()
            {
            QColor color = QColor::fromRgb(
            ui->RRGB->value(),
            ui->GRGB->value(),
            ui->BRGB->value() );
            ui->GraphicsView->setBackgroundBrush(color);
            }
            @

            moderator note: Instead of creating a new post to make corrections, please just edit your previous post instead.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Q_Tim
              wrote on last edited by
              #6

              :) Yes, I did mean to change the backgroud color.
              Thanks a lot, though it is still not yet functioning.
              I'll try to figure it out.

              [quote author="Andre" date="1320656176"]Well, you are the only one who knows of what you want to change the color. If that is the background color, then that is the background color. If it is the color of an item on the view, then do that.

              If you want to change the background color, you could do something like this:
              @
              //in your header

              Q_OBJECT // do not forget this one in the private section of your class declaration

              private slots:
              void RGB_RGBView();

              //in your implementation file:
              void MyClass::RGB_RGBView()
              {
              QColor color = QColor::fromRgb(
              ui->RRGB->value(),
              ui->GRGB->value(),
              ui->BRGB->value() );
              ui->GraphicsView->setBackgroundBrush(color);
              }
              @

              moderator note: Instead of creating a new post to make corrections, please just edit your previous post instead.[/quote]

              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