Results 1 to 4 of 4

Thread: How to display Widgets in the midle of a Window

  1. #1
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default How to display Widgets in the midle of a Window

    Following problem:

    I want to display a widget in the middle of a QMdiSubWindow. I also want to use Tabs later. Therefore I add a QStackWidget to a QMdiSubWindow. The first QStackWidget is a Widget I constructed called inAOrifice. Now in the Fullscreenmode the inAOrifice Widget isnt that big and I want to display it in the middle of the QMdiSubWindow, in the QStackWidget respectively. It always appears in the left upper corner. Any suggestions? I have tried a lot already. Cant see my mistake…

    Most common code yet …

    Qt Code:
    1. MainChild::MainChild(QWidget *parent) : QMdiSubWindow(parent)
    2. {
    3. this->setAttribute(Qt::WA_DeleteOnClose);
    4.  
    5. inAOrifice = new inputAOrifice(this);
    6. stackLayout = new QVBoxLayout(this);
    7. stackWidget = new QStackedWidget;
    8.  
    9. stackWidget->addWidget(inAOrifice);
    10. stackLayout->setAlignment(stackWidget,Qt::AlignCenter);
    11. this->setWidget(stackWidget);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: How to display Widgets in the midle of a Window

    One bug that I see is that you don't seem to add any items in your layout, so centering it does not help. You probably need to add your "orifice" into it.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to display Widgets in the midle of a Window

    For you custom widget to be centered, you need to create an empty QWidget, set a layout on to the empty widget, add custom widget on to the layout, and set center alignment to the custom widget, something like this.
    Qt Code:
    1. QWidget * widget = new QWidget;
    2. QGridLayout * layout = new QGridLayout(widget);
    3. QWidget * inAOrifice = new inputAOrifice(widget);
    4. layout->addWidget(inAOrifice);
    5. layout->setAlignment(inAOrifice, Qt::AlignCenter);
    6. // now add widget to the stacked widget
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to Santosh Reddy for this useful post:

    revellix (25th July 2011)

  5. #4
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display Widgets in the midle of a Window

    Santosh Reddy... very big thanks!!!!

Similar Threads

  1. QLogText & QLogTable : 2 widgets to display text log
    By fcoiffie in forum Qt-based Software
    Replies: 7
    Last Post: 28th April 2019, 07:52
  2. Replies: 2
    Last Post: 2nd November 2010, 15:52
  3. Replies: 0
    Last Post: 1st October 2008, 16:21
  4. Replies: 6
    Last Post: 3rd January 2008, 09:33
  5. Move QT Window to different x display
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2007, 20:28

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.