Results 1 to 6 of 6

Thread: QMainWindow resize problem

  1. #1
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default QMainWindow resize problem

    Hi,

    I have a problem with resizing QMainWindow. When I maximise or minimise the window, it sometimes happens that a part of the window falls outside the screen. In most cases, it happens when running the application on a laptop with a non-standard size screen. For example, when I maximise the screen using the maximise button and then minimise it, part of the window is not shown. For convenience I created a small demo application for this problem. This is the code:

    QApplication a(argc,argv);
    QMainWindow mwindow;
    QSize size(3000,4000);
    mwindow.setMaximumSize(size);
    mwindow.show();
    return a.exec();

    I know the size I set is rediculously large, but It is just an example, it also happens with other values. As I don't know beforehand on which size of screen the program will run, I cannot hardcode the values. Can I load the maximumsize on startup based on the size of the screen? Any other suggestions?

    Thanx!

    ps: I use QT3 on Linux, but when I try it on windows, it also has the same problem.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow resize problem

    How about using QWidget::showMaximized() instead of using such large values?

  3. #3
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow resize problem

    Hi,
    I tried that, but the problem still holds. It seems that it has to do something with a child widget that is larger dan the screen size en therefore enlarges the mainwindow. The child widget is a dockwindow and I dont't want this dockwindow to grow larger then the current mainwindowsize, ie, i don`t want my mainwindow resizing when I add a dockwindow. Kan I set the maximum size of a dockwindow to be the current mainwindowsize? I tried using QSizePolicy, but I don't see how to set the sizepolicy as setSizePolicy is a private member ....

    Wish I could post the code of the dockwindow, but unfortunately I can't (copyright). Any tips on what can go wrong could help me in digging into the dockwindows code!

    Thanx

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow resize problem

    So how come the dock widget is larger than the screen?

    QWidget::setSizePolicy() a private member? Are you sure? I think it is enough to return a proper sizeHint() from the dockwidget. And if your widget may not fit on screen, consider putting it inside QScrollArea.

  5. #5
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow resize problem

    Hi,

    I tried setSizePolicy and overwriting sizeHint, but that didn't work. I kept getting inaccessibility errors on setSizePolicy. My compiler told me setSizePolicy is a private member, but when looking in QWidget.h it is public. This is the error I get:
    " /usr/local/Trolltech/Qt-4.2.2/include/QtGui/qsizepolicy.h:148: error: 'QSizePolicy::QSizePolicy(int)' is private" I call setSizePolicy on a QMainWindow widget. It seems that the problem is in QSizePolicy and not in QMainWindow. At the moment I have no idea what's going wrong, but might this be a porting issue. We recently ported our QT3 code to QT4.

    => I looked in the header of QSizePolicy() and it seems that there is no public constructor which takes only one argument. I needed to set the size policy for both horizontal and vertical sizing. eg: myMainWindow->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::M aximum);
    myMainWindow->setSizePolicy(QSizePolicy::Maximum); thus doesn't work, altough I found void setSizePolicy(QSizePolicy) public in QWidget! QWidget also has a setSizePolicy which takes 2 arguments as the constructor of QSizePolicy. Could it be that void setSizePolicy(QSizePolicy ) is deprecated in QWidget???



    Scrolling now works fine and for now, I can use the QScrollArea to solve the problem. However in the future I would like to redesign the widget so it can fit the screen without scrolling as this would be more convenient. If I find the problem and the solution while redesigning, I will add the solution to this post, but it might take some time.

    Thanx for the help!
    Last edited by edb; 12th January 2007 at 09:30. Reason: found problem private setSizePolicy()

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow resize problem

    Quote Originally Posted by edb View Post
    I tried setSizePolicy and overwriting sizeHint, but that didn't work. I kept getting inaccessibility errors on setSizePolicy. My compiler told me setSizePolicy is a private member, but when looking in QWidget.h it is public. This is the error I get:
    " /usr/local/Trolltech/Qt-4.2.2/include/QtGui/qsizepolicy.h:148: error: 'QSizePolicy::QSizePolicy(int)' is private"
    Read the error again - it doesn't say anything about setSizePolicy... You're just using a wrong constructor for QSizePolicy class.

    I call setSizePolicy on a QMainWindow widget.
    It won't work then. Size policies apply to widgets that are inside layouts. You have to set the policy for the dock widget's contents.

    [quote]Could it be that void setSizePolicy(QSizePolicy ) is deprecated in QWidget???[/I]
    No.

Similar Threads

  1. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49
  2. How to resize a QMainWindow in QWorkspace.
    By s_a_white in forum Newbie
    Replies: 2
    Last Post: 17th July 2006, 19:22
  3. QTable resize problem with large tables
    By Robzzz in forum Newbie
    Replies: 3
    Last Post: 22nd May 2006, 15:13
  4. Replies: 16
    Last Post: 7th March 2006, 16:57
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 01:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.