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. Allow user to change table color during run-time

Allow user to change table color during run-time

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 512 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.
  • C Offline
    C Offline
    cherple
    wrote on last edited by
    #1

    Hi, i have a the following code:
    table->setStyleSheet("background-color: rgba(255, 255, 255, 10);");
    Now, i want to allow user to change the colors during run time, and i have 3 variables color_red, color_blue, color_green. The user writes the color to these 3 variables, is there any simplier way i can put these variables into the stylesheet?

    Currently what i did was:
    QString tempColor = "background-color: rgba("
    tempColor.append(color_red);
    tempColor.append(",");
    tempColor.append(color_green);
    tempColor.append(",");
    tempColor.append(color_blue);
    tempColor.append(", 10);");
    table->setStyleSheet(tempColor);

    Is there any way i can do these appends in one like?

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

      What you are looking for is:

      QString tempColor = QString("background-color: rgba(%1,%2,%3,10)").arg(color_red).arg(color_green).arg(color_blue);
      

      Oh and you could even skip the tempColor and assign directly like,

      table->setStyleSheet(QString("background-color: rgba(%1,%2,%3,10)").arg(color_red).arg(color_green).arg(color_blue));
      

      And just for the furture, you can use QString::arg() to parse arguments like your would use sprintf(). Instead of things like %d, %s, etc, you use argument numbers, i.e. %1 %2 %3 %4 ... and then each call to .arg() at the end replaces #X with the argument.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      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