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. Can't set background color
Forum Updated to NodeBB v4.3 + New Features

Can't set background color

Scheduled Pinned Locked Moved Unsolved General and Desktop
paintqt5.11
4 Posts 2 Posters 866 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.
  • T Offline
    T Offline
    timob256
    wrote on 24 Jan 2022, 13:59 last edited by timob256
    #1

    trying to set background color
    example (this work ) :

         QBrush maska(QColor(48,172,220,120),Qt::SolidPattern);      // для маски
        painter.setBrush(maska);                                           // задаём цвет фона
    

    Screenshot_20220124_165105.png

    this call code :

    case Qt::Key_A:
        if(_myTexpr.substrate)
            setSubstrate(false, 100, 100, 100, 100);
        else
            setSubstrate(true, 100, 100, 100, 100);
    
    
    void wgt_line::setSubstrate(bool val, int rgb0, int rgb1, int rgb2, int rgb3 )
    {
        _myTexpr.substrate = val;
    
        _myTexpr.substrate_t = true; // включаем датчик
    
        qDebug() << "setSubstrate(bool val, int rgb0, int rgb1, int rgb2, int rgb3 )";
        _myTexpr. rgb[0] = rgb0;
        _myTexpr. rgb[1] = rgb1;
        _myTexpr. rgb[2] = rgb2;
        _myTexpr. rgb[3] = rgb3;
     
    }
    

    and me code :

    if(_myTexpr.substrate_t == true)
        {
            color_maska.fromRgb(_myTexpr.rgb[0], _myTexpr.rgb[1], _myTexpr.rgb[2], _myTexpr.rgb[3]);
    //         color_maska(_myTexpr.rgb[0], _myTexpr.rgb[1], _myTexpr.rgb[2], _myTexpr.rgb[3]);
            maska.setColor(color_maska);    maska.setStyle(Qt::SolidPattern);
    //         maska(color_maska,Qt::SolidPattern);      // для маски
             qDebug() << "_myTexpr.suqqqqq";
        }
        if(_myTexpr.substrate_t == false)
            {
                qDebug() << "_myTexpr.substrate_t1";
                 color_maska.fromRgb(48,172,220,120);
                 maska.setColor(color_maska);    maska.setStyle(Qt::SolidPattern);
        //         maska(color_maska,Qt::SolidPattern);      // для маски
            }
        // задаём цвет фона
        if(_myTexpr.substrate == true)
            painter.setBrush(maska);
    

    Screenshot_20220124_165549.png

    For now it can only fill color with zeros which means black color :( how to set background color ???

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jan 2022, 20:39 last edited by
      #2

      Hi,

      Your logic seems wrong. Whether you press A or not, the color is 100, 100, 100, 100.

      And then you set the brush only when the color is the above set of numbers.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        timob256
        wrote on 25 Jan 2022, 09:54 last edited by timob256
        #3

        @SGaist said in Can't set background color:

        Hi,
        Your logic seems wrong. Whether you press A or not, the color is 100, 100, 100, 100.
        And then you set the brush only when the color is the above set of numbers.

        Hi

        the color is not set at all, it is 0 0 0 0 by default.

        the problem is why the color does not change


        this code work

            QBrush maska1(QColor(48,172,220,120),Qt::SolidPattern);      // для маски
                painter.setBrush(maska1);                                   // задаём цвет фона
        

        this code not work

        QBrush maska;                   // фон
        QColor color_maska;            // задаём цвет фона 
        
        color_maska.fromRgb(48,172,220,120);
        maska.setColor(color_maska);
         maska.setStyle(Qt::SolidPattern);
        painter.setBrush(maska);
        

        WHY ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 25 Jan 2022, 20:31 last edited by
          #4

          Where are you using that painter ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          3/4

          25 Jan 2022, 09:54

          • Login

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