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



  • 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!



  • 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...



  • 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]



  • 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



  • 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.



  • :) 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]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.