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. How could this be improved?
Qt 6.11 is out! See what's new in the release blog

How could this be improved?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.7k Views 2 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.
  • E Offline
    E Offline
    etla
    wrote on last edited by etla
    #1

    Ponder the current code:

    int main(int argc, char *argv[])
    {
      QApplication app(argc, argv);
    
      MainPanel *mainPanel = new MainPanel;
    
      QScrollArea *area = new QScrollArea;
      area->setWidget(mainPanel);
      area->setMaximumSize(mainPanel->size() + QSize(2, 2));
      area->resize(area->maximumSize());
      area->show();
    
      return app.exec();
    }
    
    

    This works (almost) the way I want it to, but it feels like a cludge + that there's a problem too (see point 3). So I'm wondering:

    1. Shouldn't this be possible to solve with policies instead of brute forcing the size? I've tried but I can't get it to work as I want it to.

    2. Why do I have to add QSize(2, 2) to the maximum size to get rid of the scroll bars? Sounds like a bug to me. (This might of course be solved with 1?)

    3. Forcing the window to a size like this doesn't respect actual screen size. MainPanel is (to be exact) 2722x828 pixels which works nice on my 4K screen, but my colleges that's gonna run this has smaller screens and that means that the window goes "out of screen". How can I make the program limit it's window size to max screen width?

    Code in haste; debug in leisure.

    JKSHJ 1 Reply Last reply
    0
    • E Offline
      E Offline
      etla
      wrote on last edited by
      #2

      Ok, solved bullet 3 with another cludge I guess (and added menus as well, thus the extra code compared to above). It works, but isn't there a cleaner way to do this or should I consider this kosher?

      int main(int argc, char *argv[])
      {
        QApplication app(argc, argv);
      
        MainPanel *mainPanel = new MainPanel;
      
        QScrollArea *area = new QScrollArea;
        area->setWidget(mainPanel);
        area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        area->setMaximumSize(mainPanel->size() + QSize(2, 0));
        area->setMinimumHeight(mainPanel->height());
      
        MainWindow *mainWindow = new MainWindow(mainPanel);
        mainWindow->setCentralWidget(area);
        mainWindow->setMaximumWidth(mainPanel->width() + 2);
        QDesktopWidget desktop;
        mainWindow->resize(desktop.geometry().width(), mainPanel->height());
      
        mainWindow->show();
      
        return app.exec();
      }
      
      

      Code in haste; debug in leisure.

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

        Hi,

        Why not use showMaximized ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        E 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          Why not use showMaximized ?

          E Offline
          E Offline
          etla
          wrote on last edited by
          #4

          @SGaist Mostly because I didn't realize it existed. ;)

          I could use that as a cleaner solution instead of the mainWindow->resize, but then I have to constrain the maximumSize in a good way too. Is there a way to tell that the window should never be bigger than the max size of MainPanel + the size of the meny, status bar etc? If I use maximumSize the window gets expanded to full screen height which looks rather ugly.

          Code in haste; debug in leisure.

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

            What are the ideal dimensions of your application ?

            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
            0
            • E etla

              Ponder the current code:

              int main(int argc, char *argv[])
              {
                QApplication app(argc, argv);
              
                MainPanel *mainPanel = new MainPanel;
              
                QScrollArea *area = new QScrollArea;
                area->setWidget(mainPanel);
                area->setMaximumSize(mainPanel->size() + QSize(2, 2));
                area->resize(area->maximumSize());
                area->show();
              
                return app.exec();
              }
              
              

              This works (almost) the way I want it to, but it feels like a cludge + that there's a problem too (see point 3). So I'm wondering:

              1. Shouldn't this be possible to solve with policies instead of brute forcing the size? I've tried but I can't get it to work as I want it to.

              2. Why do I have to add QSize(2, 2) to the maximum size to get rid of the scroll bars? Sounds like a bug to me. (This might of course be solved with 1?)

              3. Forcing the window to a size like this doesn't respect actual screen size. MainPanel is (to be exact) 2722x828 pixels which works nice on my 4K screen, but my colleges that's gonna run this has smaller screens and that means that the window goes "out of screen". How can I make the program limit it's window size to max screen width?

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #6

              @etla said in How could this be improved?:

              1. Shouldn't this be possible to solve with policies instead of brute forcing the size? I've tried but I can't get it to work as I want it to.

              You could place the scroll area(s) inside the main panel, instead of the other way round.

              1. Why do I have to add QSize(2, 2) to the maximum size to get rid of the scroll bars? Sounds like a bug to me. (This might of course be solved with 1?)

              QScrollArea is designed to make a larger widget shrink to fit inside a constrained space. Your use-case (expanding the QScrollArea to make it fit the larger widget) is less common.

              To put it another way: People normally use QScrollArea when they want scrollbars. That's why it's cludgy to make it get rid of scrollbars ;)

              1. Forcing the window to a size like this doesn't respect actual screen size. MainPanel is (to be exact) 2722x828 pixels which works nice on my 4K screen, but my colleges that's gonna run this has smaller screens and that means that the window goes "out of screen". How can I make the program limit it's window size to max screen width?

              Use QScreen or QDesktopWidget to query the screen size and write some simple logic to adjust your app's window size accordingly.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              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