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. using QRegExp and Validator in Stylesheet?
Forum Updated to NodeBB v4.3 + New Features

using QRegExp and Validator in Stylesheet?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 517 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.
  • A Offline
    A Offline
    aravmadd
    wrote on last edited by aravmadd
    #1

    In my header file i am using like this for all my lineEdit objects

                 #define length 6
                  #define display "XxYy00"
                  #define format"^[A-Z]{1,1}[a-z]{1,1}[A-Z]}$"
    		QRegExp idFormat(TEST_ID_FORMAT);
    		QRegExpValidator *testIDValidator = new QRegExpValidator(idFormat);
    		
    
    		test0->setValidator(testIDValidator);
    		test0->setText(display );
    		test0->setMaxLength(length );
    		test0->setAlignment(Qt::AlignCenter);
    		test0->setFont(textFont);
    

    However instead of doing this stuff in header file i would like to try this to implement via StyleSheets. I think this can be possible in stylesheet and i tried like this

    In my lineEdit i did change StyleSheet and added like this

    QLineEdit:
    {
    	TEST_ID_FORMAT "^[A-Z]{1,1}[a-z]{1,1}[A-Z]{1,1}[a-z]{1,1}[0-9]{1,1}[0-9]{1,1}$";
            QRegExp idFormat(TEST_ID_FORMAT);
            QRegExpValidator *testIDValidator = new QRegExpValidator(idFormat);
    }
    

    It seems to be i am doing some wrong but i am unable to find it till now :-(. All this setMaxLenght are not implemented in this stylesheet but i will be doing it later if it works :-)

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

      Hi,

      Do I understand correctly that you are trying to instanciate C++ object in 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

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do I understand correctly that you are trying to instanciate C++ object in a style sheet ?

        A Offline
        A Offline
        aravmadd
        wrote on last edited by aravmadd
        #3

        @SGaist No, But what i am trying to say was like normally till now for example in my lineEdit object i always restrict to enter only data which is like ip address(P.S the code showed in the question was bit different but idea is still same) by using validator and RegExp. And I am asking if i can do the same using stylesheets? I mean i want this information to be in stylesheets which will be embedded in ui file.

        What i mean by doing using stylesheets means can i use validator and Regexp in stylesheets and remove that code part in my header file?

        I would like to know if there is such method. I did tried to search in qt forum and also in stack but from what i found was there is no such way or may be even i understood wrong by reading few things.

        JonBJ 1 Reply Last reply
        0
        • A aravmadd

          @SGaist No, But what i am trying to say was like normally till now for example in my lineEdit object i always restrict to enter only data which is like ip address(P.S the code showed in the question was bit different but idea is still same) by using validator and RegExp. And I am asking if i can do the same using stylesheets? I mean i want this information to be in stylesheets which will be embedded in ui file.

          What i mean by doing using stylesheets means can i use validator and Regexp in stylesheets and remove that code part in my header file?

          I would like to know if there is such method. I did tried to search in qt forum and also in stack but from what i found was there is no such way or may be even i understood wrong by reading few things.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @aravmadd
          Style sheets (CSS, QSS) are for visual style. You can't put regular expressions or validators or similar into style.

          A 1 Reply Last reply
          2
          • JonBJ JonB

            @aravmadd
            Style sheets (CSS, QSS) are for visual style. You can't put regular expressions or validators or similar into style.

            A Offline
            A Offline
            aravmadd
            wrote on last edited by
            #5

            @JonB Thanks for the clarity information. I was thinking the same .

            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