Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Stylesheet in QHBoxLayout embedded in QFormLayout

    General and Desktop
    stylesheet qhboxlayout qformlayout fontsize
    2
    3
    2734
    Loading More Posts
    • 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.
    • G
      gabor53 last edited by

      Hi,
      I have the following code:

      #include "additem.h"
      #include "ui_additem.h"
      
      Additem::Additem(QWidget *parent) :
          QDialog(parent),
          ui(new Ui::Additem)
      {
          ui->setupUi(this);
      
      	Addcontent ();
      
      
      }
      
      Additem::~Additem()
      {
          delete ui;
      }
      
      void Additem::Addcontent()
      {
      
      //Add Title
      
          QLabel  *Title	= new QLabel;
          QFont f("Arial", 18, QFont::Bold);
          Title->setFont (f);
          Title->setAlignment (Qt::AlignCenter);
          Title->setText ("ADDING A FRIEND TO THE DATABASE");
          Title->setFixedWidth (840);
          Title->show ();
      
      //Add ID Counter
      
          Additem::opendb ();
      
          QSqlQuery query("SELECT ID FROM Items ORDER BY ID DESC");
      
          if(query.isActive()==true)
              {
                  qDebug() << "The query is active.";
              }
          else
              {
                  qDebug() << "The query is NOT active.";
              }
      
          query.first ();
          int LastID;
          LastID = query.value(0).toInt ();
      
          qDebug() << "The last ID is " << LastID;
      
          int ItemID = LastID+1;
      
          qDebug() << "The Item ID # is " << ItemID;
          QString sID = QString::number(ItemID);
      
          QLabel *Label_ID = new QLabel;
          QFont g("Arial", 16, QFont::Normal);
          Label_ID->setFont (g);
      
          QLabel *ID_Display = new QLabel;
          ID_Display->setFont (g);
      
      
          Label_ID ->setText ("Friend ID:");
          ID_Display ->setText (sID);
      
          db.close ();
      
      
      //Getting name
          QLabel *Label_Name = new QLabel;
          Label_Name->setFont (g);
          Label_Name->setText ("Name:");
      
          QLineEdit *LineEdit_Name = new QLineEdit;
          LineEdit_Name->setFont (g);
      
          QString string;
      
          string = LineEdit_Name->text ();
          setFocusPolicy (Qt::StrongFocus);
          connect(LineEdit_Name, SIGNAL(editingFinished()), this, SLOT(readAndValidate()));
      
          setStyleSheet("QLineEdit{ "
                        "background-color:rgb(202, 255, 227);"
                        "border: 2px solid gray;"
                        "border-radius: 10px;"
                        "padding: 0 8px;"
                        "selection-background-color: darkgray;"
                        "font-size: 16px;}"
                        "QLineEdit:focus { "
                        "background-color:rgb(192, 192, 255);}"
                        );
      
          LineEdit_Name->setFixedWidth (150);
          LineEdit_Name->setFixedHeight (35);
      
          //validating
      
          QLabel *angry_image_Label = new QLabel;
      
          angry_image_Label->setFixedSize (30,30);
      
      //    QLabel *incorrect_Label = new QLabel();
      //    incorrect_Label->setStyleSheet("QLabel { font-size:200px; color: red; }");
          QLabel *incorrect_Label = new QLabel();
          incorrect_Label->setStyleSheet("QLabel { font-size:200px; color: red; }");
          //incorrect_Label->show();
      
      
                       if(string.length ()<2)
                         {
                             incorrect_Label->setText ("The name is too short!");
                             incorrect_Label->setStyleSheet ("color: red");
      
                             QPixmap pix("C:/Programming/Projects/FolkFriends/icons/angry.png");
      
                             angry_image_Label->setScaledContents (true);
                             angry_image_Label->setPixmap (pix);
                         }
                         else
                         {
                             incorrect_Label->setText ("");
                             QPixmap pix2("C:/Programming/Projects/FolkFriends/icons/Check-icon.png");
                             angry_image_Label->setScaledContents (true);
                             angry_image_Label->setPixmap (pix2);
                         }
      
                     QString Name;
                     Name = LineEdit_Name->text ();
                     qDebug() << "Name: " << Name;
      
      
      //Creating the scroll area
      
          	QScrollArea *scrollarea = new QScrollArea(this);
              scrollarea->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
              scrollarea->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
      
              scrollarea->setMinimumWidth (900);
      
              QWidget *viewport  = new QWidget(this);
              scrollarea->setWidget (viewport);
              scrollarea->setWidgetResizable (true);
      
              QFormLayout *layout = new QFormLayout(this);
              viewport->setLayout (layout);
      		layout->setSpacing (60);
      
              //Title Row setup
              QHBoxLayout *titleRow = new QHBoxLayout();
              titleRow->addWidget (Title);
      
      		//Creating the Name row
      
      		QHBoxLayout *NameRow = new QHBoxLayout();
      
              NameRow->addWidget (Label_Name);        
              NameRow->addWidget (LineEdit_Name);
              NameRow->addSpacing (10);
              NameRow->addWidget (angry_image_Label);
              NameRow->addSpacing (10);
              NameRow->addWidget (incorrect_Label);
      		NameRow->addSpacing (350);
      
              //Interspace
              layout->setVerticalSpacing (30);
              QLabel *spacer_Label = new QLabel;
      
              //Displaying the rows
      
      		layout->addRow (titleRow);
              layout->addRow (spacer_Label,spacer_Label);
              layout->addRow (Label_ID,ID_Display);
              layout->addRow (NameRow);
      
      }
      

      The incorrect_Label's formatting does not show when displayed in the layout. It shows when I display it outside of the layout. The color is correct even in the layout. What can I do to increase the text size of incorrect_Label?
      Thank you for your help.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You are applying several different style sheets on your widget for QLineEdit. Either remove the QLineEdit specifier on incorrect_Label or use an object name to differentiate it.

        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 Reply Quote 1
        • G
          gabor53 last edited by

          Thank you!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post