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. I need a Spin Control. Can I make a spin box without the text box?

I need a Spin Control. Can I make a spin box without the text box?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 5.2k 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.
  • K Offline
    K Offline
    kenchan
    wrote on last edited by
    #1

    Hello,

    I want to have the equivalent of a Windows spin control ie. just the spinner arrows with no text box attached. I have done this using a very small scrollbar which works fine on Windows but it does not work on the Mac because there are no arrows on the Mac scrollbars??

    The spin box has the arrows on the Mac so Is there a way to kill the text box an just have spinner arrows?
    Can anyone recommend another way of implementing this which does not require doing everything myself from basic widgets?

    Or, is there a way to display the arrows on the Mac?

    I will be very grateful for any other suggestions.

    Many thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mehrdadsilver
      wrote on last edited by
      #2

      You can use stylesheet & set arrows with icons suitable for Mac.

      Mehrdad Abdolghafari, Be silver

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        what happens when you do the following?
        @
        mySpinBox->lineEdit()->hide();
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kenchan
          wrote on last edited by
          #4

          Thanks for the suggestion raven-worx.

          I found that the edit box is a protected member of QAbstractSpinBOx so its hide method cannot be accessed from QSpinBox.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kenchan
            wrote on last edited by
            #5

            Thank you for your suggestion mehrdadsilver.

            I will look into that but I am not sure how I can style buttons that don't already exist on the control??

            can you please show me how that would look in a style sheet?

            Thanks

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              [quote author="kenchan" date="1379923919"]Thanks for the suggestion raven-worx.

              I found that the edit box is a protected member of QAbstractSpinBOx so its hide method cannot be accessed from QSpinBox.
              [/quote]
              Yes, you need to subclass it then.
              @
              MySpinBox::MySpinBox(QWidget* parent)
              : QSpinBox(parent)
              {
              this->lineEdit()->hide();
              }
              @

              I#m not sure that it will work as expected, but worth a try IMHO.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kenchan
                wrote on last edited by
                #7

                I tried to subclass it but I get the same compiler error because the lineEdit object is a protected member of QAbstractSpinBox.

                @
                class MySpinBox : public QSpinBox
                {
                Q_OBJECT

                public:
                MySpinBox(QWidget* parent);
                };

                MySpinBox::MySpinBox(QWidget* parent)
                : QSpinBox(parent)
                {
                lineEdit()->hide();
                }
                @

                error: C2248: 'QAbstractSpinBox::lineEdit' : cannot access protected member declared in class 'QAbstractSpinBox'

                Is there another way to do this?

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  Are you sure you are using your MySpinBox class at all? Your code is correct, thus it should definitely work.

                  Does the C2248 compiler error really come from the line in the MySpinBox constructor?!

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kenchan
                    wrote on last edited by
                    #9

                    Sorry my mistake. I was able to get rid of the compiler error but not the line edit. It will not hide and I can't change the geometry to make it smaller.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kenchan
                      wrote on last edited by
                      #10

                      Hello Again,

                      This one looks like a dead and. I don't think I am going to be able to hide the line edit without subclassing QAbstractSpinBox or something. My other alternative is to make my own control to do this which I don't have time to do right now.

                      If anyone has any more ideas they will be very much appreciated.

                      Thanks again.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        delos
                        wrote on last edited by
                        #11

                        Hello

                        Just signed up here because I have the same issue.
                        So first of all, hello world ;-)

                        This thread is quite old, but is it still not possible to create a sole spin control without text field?

                        Cheers
                        delos

                        JonBJ 1 Reply Last reply
                        0
                        • D delos

                          Hello

                          Just signed up here because I have the same issue.
                          So first of all, hello world ;-)

                          This thread is quite old, but is it still not possible to create a sole spin control without text field?

                          Cheers
                          delos

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @delos
                          I don't believe the preceding discussion necessarily exhausted all the possibilities.

                          I would try to do it via stylesheet and hiding of the line edit, if that's possible. I'm sorry but I am too tired to look up how you address the line edit this way, you'll have to find the refence section in the Qt docs for stylsheets & widgets.

                          Or, since there is https://doc.qt.io/qt-5/qabstractspinbox.html#setLineEdit, even if you can't hide the inbuilt one I would have thought this really ought allow you control over your own line edit.

                          D 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @delos
                            I don't believe the preceding discussion necessarily exhausted all the possibilities.

                            I would try to do it via stylesheet and hiding of the line edit, if that's possible. I'm sorry but I am too tired to look up how you address the line edit this way, you'll have to find the refence section in the Qt docs for stylsheets & widgets.

                            Or, since there is https://doc.qt.io/qt-5/qabstractspinbox.html#setLineEdit, even if you can't hide the inbuilt one I would have thought this really ought allow you control over your own line edit.

                            D Offline
                            D Offline
                            delos
                            wrote on last edited by
                            #13

                            @JonB

                            Thanks for the quick answer. Since QLinedit seems to be protected, I don't have access. Furthermore, I don't find away how to e.g. set the width of the text box.
                            Anyway, I'll try with style sheets. Since I just started with Qt, it will take a while. Whenever I found a solution I will report on it.

                            Cheers
                            delos

                            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