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 size of QScrollArea viewport before showing

Get size of QScrollArea viewport before showing

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views
  • 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.
  • karl_simmonsK Offline
    karl_simmonsK Offline
    karl_simmons
    wrote on last edited by
    #1

    I have a custom QDialog comprised of a QStackedWidget with QScrollArea widgets for each page of the stacked widget.

    I want to set the size hint for the QDialog such that the dialog is large enough that the scroll bars for the scroll area are not visible when the dialog is first shown (i.e. ensure size of QScrollArea viewport = size hint of child widget in scroll area). Currently, the default sizeHint() implementation for the QDialog has insufficient height, which causes the vertical scroll bar to be shown when first loaded.

    I thought this could be achieved by re-implementing sizeHint() for the QDialog, whereby the size hint of the dialog would be adjusted by the amount required for the size of QScrollArea viewport to equal the size hint for child widget in the scroll area (for the first page of the stacked layout). Unfortunately, in sizeHint(), the size of the QScrollArea viewport is set to the default size of QStackedWidget (640x480), and only updates to the correct size once the QDialog is shown.

    Is there some way to get the correct size of the QScrollArea viewport before it is shown, or another way to achieve the desired effect of adjusting the size hint of the dialog to prevent scroll bars from being shown when it is first displayed (aside from hard-coding the dialog size)?

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

      Hi and welcome

      Have you tried with virtual
      void Mydialog::showEvent ( QShowEvent * e)
      {
      // do what u need
      QDialog::showEvent(e);
      }

      It its called just before the dialog is shown so all sizes should be set.

      karl_simmonsK 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi and welcome

        Have you tried with virtual
        void Mydialog::showEvent ( QShowEvent * e)
        {
        // do what u need
        QDialog::showEvent(e);
        }

        It its called just before the dialog is shown so all sizes should be set.

        karl_simmonsK Offline
        karl_simmonsK Offline
        karl_simmons
        wrote on last edited by
        #3

        @mrjj Your solution worked perfectly. Thanks!

        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