Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to apply colors to a box/subwindow within mainwindow?
Forum Updated to NodeBB v4.3 + New Features

How to apply colors to a box/subwindow within mainwindow?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 3 Posters 2.1k Views 2 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.
  • S Offline
    S Offline
    Sherlin N G
    wrote on last edited by
    #1

    I have created a QColordialog below is the screenshot0_1519654429501_color_virtual.png where user selects a color and the color should be applied in the below box/subwindow.Please suggest

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What's that "below box/subwindow" ?

      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
      • S Offline
        S Offline
        Sherlin N G
        wrote on last edited by
        #3

        @SGaist
        Hi,
        I have put a QMdiArea(it can be anything).When user selects the color the region should be colored correspondingly.Is it possible?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          So it would be the background color ?

          There are several possibilities depending on what you are going to use.

          The most quick and simple would using a style sheet.

          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
          • S Offline
            S Offline
            Sherlin N G
            wrote on last edited by
            #5

            @SGaist
            the selected color has to be applied to the region below.Please suggest what kind of region should be used to do this.I tried applying stylesheets on mdiarea its not working

            mrjjM 1 Reply Last reply
            0
            • S Sherlin N G

              @SGaist
              the selected color has to be applied to the region below.Please suggest what kind of region should be used to do this.I tried applying stylesheets on mdiarea its not working

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Sherlin-N-G

              Hi
              Stylesheets surely works as i used them a lot :)

              Can you provide more detail of what you call "the region."
              Is it same area, is it many different widgets ?
              What do you want to color ?
              Its not enough to say "applied to the region below" since the answer depends on what you are really trying :)

              1 Reply Last reply
              1
              • S Offline
                S Offline
                Sherlin N G
                wrote on last edited by
                #7

                @mrjj
                Hi,Thanks for the reply.

                Its a label.How can I set stylesheets to that label based on users selection from the QColorDialog.

                mrjjM 1 Reply Last reply
                0
                • S Sherlin N G

                  @mrjj
                  Hi,Thanks for the reply.

                  Its a label.How can I set stylesheets to that label based on users selection from the QColorDialog.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Sherlin-N-G
                  hi
                  You would generate the stylesheetstring

                  
                  #include <QColorDialog>
                  
                  QString sheet = R"(
                  QLabel#label {
                  background-color: %1;
                  }
                  )";
                  
                  void SetColor(QWidget *w ) {
                  if( !w ) return;
                  QColor color = QColorDialog::getColor(Qt::yellow);
                  if( color.isValid() ) {  
                    w->setStyleSheet( sheet.arg(color.name()) );
                   }
                  }
                  

                  // call it like
                  SetColor(ui->label);

                  Note label must be called "label" or yo should adjust name in string.

                  1 Reply Last reply
                  3

                  • Login

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