Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Set QLineEdit nur fün double Zahlen, die nicht grösse als 5.0 sind beim Qt4
Forum Updated to NodeBB v4.3 + New Features

Set QLineEdit nur fün double Zahlen, die nicht grösse als 5.0 sind beim Qt4

Scheduled Pinned Locked Moved Solved German
7 Posts 3 Posters 2.6k 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.
  • G Offline
    G Offline
    Galilio
    wrote on last edited by
    #1

    Hallo,

    wie setze ich das QLineEdit, dass es nur double Zahlen (nicht gösse als 5.0) editierbar sind?

    Ich habe es folgende versucht:

    ui.myLineEdit->setVoltage (new QDoubleValidator(0,5, 2, this));
    

    aber somit kann ich nur zeichen verhindern

    Danke in voraus

    K 1 Reply Last reply
    0
    • G Galilio

      Hallo,

      wie setze ich das QLineEdit, dass es nur double Zahlen (nicht gösse als 5.0) editierbar sind?

      Ich habe es folgende versucht:

      ui.myLineEdit->setVoltage (new QDoubleValidator(0,5, 2, this));
      

      aber somit kann ich nur zeichen verhindern

      Danke in voraus

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Galilio

      Was ist setVoltage?

      sollte nicht setValidator sein?

      Vote the answer(s) that helped you to solve your issue(s)

      G 1 Reply Last reply
      0
      • K koahnig

        @Galilio

        Was ist setVoltage?

        sollte nicht setValidator sein?

        G Offline
        G Offline
        Galilio
        wrote on last edited by
        #3

        @koahnig

        gedanklich war ich richtig aber was geschrieben ist falsch
        :-)

        QRegExp rx("[0-4].[0-9]");
        ui.myLineEdit(new QRegExpValidator(rx, this));
        

        So muss es passen oder?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Galilio
          wrote on last edited by
          #4

          Das stimmt wieder nicht ganz:

          QRegExp rx("[0-4].[0-9]");
          ui.myLineEdit->setValidator((new QRegExpValidator(rx, this));
          

          aber ich kann doch 123 eingeben und das muss verhindert werden.

          J.HilkJ 1 Reply Last reply
          0
          • G Galilio

            Das stimmt wieder nicht ganz:

            QRegExp rx("[0-4].[0-9]");
            ui.myLineEdit->setValidator((new QRegExpValidator(rx, this));
            

            aber ich kann doch 123 eingeben und das muss verhindert werden.

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Galilio mal ganz dumm gefragt,
            warum muss es denn ein QLineEdit sein?

            Für einen double würde ich QDoubleSpinBox nehmen.

            setRange(double min double max)
            &
            setSingleStep(double val)

            brauchst du dann nur für die Konfiguration

            Wess es um's aussehen geht, kannst du das locker wie nen QLineEdit aussehen lassen, via QStyleSheet.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            G 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @Galilio mal ganz dumm gefragt,
              warum muss es denn ein QLineEdit sein?

              Für einen double würde ich QDoubleSpinBox nehmen.

              setRange(double min double max)
              &
              setSingleStep(double val)

              brauchst du dann nur für die Konfiguration

              Wess es um's aussehen geht, kannst du das locker wie nen QLineEdit aussehen lassen, via QStyleSheet.

              G Offline
              G Offline
              Galilio
              wrote on last edited by
              #6

              @J.Hilk

              Du hat vollkommen recht.
              Es macht sinn der QDoubleSpinBox zu nehmen.
              Wegen das aussehen wie stelle es das in QtDesigner, dass es genau wie QlineEdit aussieht?

              Danke

              J.HilkJ 1 Reply Last reply
              0
              • G Galilio

                @J.Hilk

                Du hat vollkommen recht.
                Es macht sinn der QDoubleSpinBox zu nehmen.
                Wegen das aussehen wie stelle es das in QtDesigner, dass es genau wie QlineEdit aussieht?

                Danke

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Galilio
                schau mal hier sind Beispiele wie man QStyleSheet nutzen kann. Ich hab mal eben das Beispiel von QSpinBox genommen und auf das hier reduziert:

                QDoubleSpinBox {
                    padding-right: 15px; /* make room for the arrows */
                    border-width: 3;
                }
                
                QDoubleSpinBox::up-button {
                    subcontrol-origin: border;
                    subcontrol-position: top right; /* position at the top right corner */
                
                    width: 16px; /* 16 + 2*1px border-width = 15px padding + 3px parent border */
                    border-image: url(:/images/spinup.png) 1;
                    border-width: 1px;
                }
                
                QDoubleSpinBox::down-button {
                    subcontrol-origin: border;
                    subcontrol-position: bottom right; /* position at bottom right corner */
                
                    width: 16px;
                    border-image: url(:/images/spindown.png) 1;
                    border-width: 1px;
                    border-top-width: 0;
                }
                

                sieht schon sehr nach QLineEdit aus.
                Ich denke die Buttons werden nicht gezeichnet, weil die border-images nicht existieren.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                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