Results 1 to 11 of 11

Thread: Widget->show() place widget to top left corner (not on the top of mainwindow)

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Widget->show() place widget to top left corner (not on the top of mainwindow)

    Hi,

    I have a main window and on menu item click I open new modal window with method show(). Sometimes happens that application is in the middle of the screen but new window is opened on the top left corner. I would need to always open widget near the mainwindow. It's possible to have such a behaviour? I'm using Qt 4.6.2 on winXP. Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    You parent your pupup dialog with the window/dialog you want to to be centered on.
    Or, if parenting is not wanted for what ever reason, you can test its position and move it, either by using move() or setGeometry().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    Hi,

    popup dialogs are parent for mainwindow. So it should work and show popup near the mainwindow.
    I'm using it in that way in main window constructor:
    Qt Code:
    1. /* new dialog */
    2. this->about = new DialogAbout(parent);
    To copy to clipboard, switch view to plain text mode 

    Then slot for click I do:
    Qt Code:
    1. about->show();
    To copy to clipboard, switch view to plain text mode 

    I have similar for 4 more widget and they are always shown correctly.

    How can I check position of main window to use your second advice?
    I try to use dialog->pos() but always get QPoint(0,0).

    Thanks

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    I'm not sure that i understand your code, but:
    this:
    Qt Code:
    1. this->about = new DialogAbout(parent);
    To copy to clipboard, switch view to plain text mode 
    shouldn't be like this?
    Qt Code:
    1. this->about = new DialogAbout(this);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    Hi,

    it doesn't help. Any other advices ? Thanks

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    If you can't post your code, please make a small project that has that behavior and post it.

  7. #7
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    No problem. See attachment.
    Attached Files Attached Files

  8. #8
    Join Date
    May 2010
    Posts
    24
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    Your form should inherit from QDialog, so it can be a top-level window, have a parent and be centered on top of that parent.

    And as Zlatomir said, you should pass this to its constructor:
    Qt Code:
    1. this->form = new Form(this);
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to alexisdm for this useful post:

    Zlatomir (29th May 2010)

  10. #9
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    Hi,

    I think (parent) is OK. If I use your proposals then my mainwindow is mixed with form widget. Did you try it you just assume it should be in that way? Thanks

  11. #10
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    If you make it a dialog it works like you want (or at least like i think you want)

    And i don't recommend to make the Form member in MainWindow (check the code)
    You can emit a signal (a MainWindow signal) when member button is clicked, and connect that with the show() slot of your Form (that's what on_bla_bla slots do with auto-connect, or you can manualy connect them)
    Attached Files Attached Files
    Last edited by Zlatomir; 29th May 2010 at 18:41.

  12. #11
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget->show() place widget to top left corner (not on the top of mainwindow)

    Hmm, I think this doesn't solve my situation. I need to mention I use 5 same widgets which I show with show() method and only 1 of them make a problem (is displayed at the top left corner). With my attachment I would like to show you whats the problem. It's rather strange for me why this happens because I use it is same way.

Similar Threads

  1. How to Disabel close button on top corner of widget
    By jsmith in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2010, 16:57
  2. QTabWidget: corner widget is not shown
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2008, 17:30
  3. Replies: 5
    Last Post: 29th August 2007, 16:36
  4. Corner widget in QTabWidget doesn't show up
    By ePharaoh in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2006, 17:02
  5. [qt4] QScrollArea corner widget?
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2006, 21:42

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.