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. Get screensize
Forum Updated to NodeBB v4.3 + New Features

Get screensize

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 3 Posters 3.4k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #10

    Yeah I'm right but I shouldn't be :D RTL should not invert numbers, as far as I know, only regular text.

    Perhaps this will work better (https://doc.qt.io/qt-5/qlocale.html#toString-6):

    QLocale::toString(size.width()) + " x " + QLocale::toStringsize.height())
    

    (Z(:^

    N 1 Reply Last reply
    0
    • JonBJ JonB

      @Natural_Bugger
      Well the code looks right to me now. Just in case, what does qApp->screens().count() return ?

      I'm "surprised" at one thing. Your output 0801 & 0291 have leading 0s, and are 4 digits long. That does not look like the default output from QString::number(), what is going on?

      EDIT Oh, I see what @sierdzio is saying below. If you read them right-to-left then you do get 1920 x 1080. I think somewhere you have indeed set for Right-to-Left text output! Change your string " x " over to " <<< " and see which direction those chevrons come out --- is it indeed >>>?! EDIT My bad. Corrected in my post below.

      N Offline
      N Offline
      Natural_Bugger
      wrote on last edited by
      #11

      @JonB said in Get screensize:
      I think somewhere you have indeed set for Right-to-Left text output! Change your string " x " over to " <<< " and see which direction those chevrons come out --- is it indeed >>>?!

      thank you for your answer.

      chevrons?

      what do i need to do?

      JonBJ 1 Reply Last reply
      0
      • N Natural_Bugger

        @JonB said in Get screensize:
        I think somewhere you have indeed set for Right-to-Left text output! Change your string " x " over to " <<< " and see which direction those chevrons come out --- is it indeed >>>?!

        thank you for your answer.

        chevrons?

        what do i need to do?

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

        @Natural_Bugger said in Get screensize:

        what do i need to do?

        I told you. Change your string " x " to " <<< ", how much clearer can I be?

        msgBox.setText(QString::number(size.width()) + " <<< " + QString::number(size.height()));
        

        EDIT I'm sorry, my bad, I've just realized I was thinking too literally, like a mirror!

        Try:

        msgBox.setText(QString::number(size.width()) + " abc " + QString::number(size.height()));
        

        I want to know whether that comes out as abc or as cba?

        N 1 Reply Last reply
        0
        • sierdzioS sierdzio

          Yeah I'm right but I shouldn't be :D RTL should not invert numbers, as far as I know, only regular text.

          Perhaps this will work better (https://doc.qt.io/qt-5/qlocale.html#toString-6):

          QLocale::toString(size.width()) + " x " + QLocale::toStringsize.height())
          
          N Offline
          N Offline
          Natural_Bugger
          wrote on last edited by
          #13

          @sierdzio said in Get screensize:

          Yeah I'm right but I shouldn't be :D RTL should not invert numbers, as far as I know, only regular text.

          Perhaps this will work better (https://doc.qt.io/qt-5/qlocale.html#toString-6):

          QLocale::toString(size.width()) + " x " + QLocale::toStringsize.height())
          
          #include <QLocale>
          

          returns

          error: cannot call member function ‘QString QLocale::toString(int) const’ without object                                                                      ^
          
          sierdzioS 1 Reply Last reply
          0
          • JonBJ JonB

            @Natural_Bugger said in Get screensize:

            what do i need to do?

            I told you. Change your string " x " to " <<< ", how much clearer can I be?

            msgBox.setText(QString::number(size.width()) + " <<< " + QString::number(size.height()));
            

            EDIT I'm sorry, my bad, I've just realized I was thinking too literally, like a mirror!

            Try:

            msgBox.setText(QString::number(size.width()) + " abc " + QString::number(size.height()));
            

            I want to know whether that comes out as abc or as cba?

            N Offline
            N Offline
            Natural_Bugger
            wrote on last edited by
            #14

            @JonB

            it return: cba

            JonBJ 1 Reply Last reply
            0
            • N Natural_Bugger

              @JonB

              it return: cba

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

              @Natural_Bugger
              Yup! So we are all agreed: there is right-to-left going on here, the results of the screen size are correct but are being printed right-to-left! Not my area, but that is what needs sorting out....

              N 1 Reply Last reply
              0
              • N Natural_Bugger

                @sierdzio said in Get screensize:

                Yeah I'm right but I shouldn't be :D RTL should not invert numbers, as far as I know, only regular text.

                Perhaps this will work better (https://doc.qt.io/qt-5/qlocale.html#toString-6):

                QLocale::toString(size.width()) + " x " + QLocale::toStringsize.height())
                
                #include <QLocale>
                

                returns

                error: cannot call member function ‘QString QLocale::toString(int) const’ without object                                                                      ^
                
                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #16

                @Natural_Bugger ok it's not a static method, eh.

                Then:

                QLocale locale;
                msgBox.setText(locale.toString(size.width()) + " x " + locale.toStringsize.height()));
                

                (Z(:^

                1 Reply Last reply
                0
                • JonBJ JonB

                  @Natural_Bugger
                  Yup! So we are all agreed: there is right-to-left going on here, the results of the screen size are correct but are being printed right-to-left! Not my area, but that is what needs sorting out....

                  N Offline
                  N Offline
                  Natural_Bugger
                  wrote on last edited by
                  #17

                  @JonB @sierdzio

                  i found the error.

                  i used a custom button class, i found online and it contains a method to reverse the text.

                  void CustomButton::reverseText()
                  {
                      QString buttonText = text();
                      std::reverse(buttonText.begin(), buttonText.end());
                      setText( buttonText );
                  }
                  

                  : )

                  thank you both

                  JonBJ 1 Reply Last reply
                  0
                  • N Natural_Bugger

                    @JonB @sierdzio

                    i found the error.

                    i used a custom button class, i found online and it contains a method to reverse the text.

                    void CustomButton::reverseText()
                    {
                        QString buttonText = text();
                        std::reverse(buttonText.begin(), buttonText.end());
                        setText( buttonText );
                    }
                    

                    : )

                    thank you both

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

                    @Natural_Bugger
                    Using a custom button which calls reverse is not a good place to start from....

                    But I don't understand, the code you gave us uses QMessageBox::setText(), which is what we looked at, what has that got to do with any custom button, or the reverseText() method?

                    1 Reply Last reply
                    1
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #19

                      Hah, ok good that you've found it. Happy coding!

                      (Z(:^

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved