Results 1 to 5 of 5

Thread: Operation of 'show'

  1. #1
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Operation of 'show'

    I am creating a widget that is similar to another created in a different GUI.
    If I do basewin->show() in the constructor, I get what I expect to see, the widget is displayed.
    The constructor code is below.

    ProgressBar::ProgressBar( QWidget *parent )
    : QWidget(parent)
    {
    QRect newrct;
    QRect qrct = parent->geometry();
    basewin = new QDialog( this, Qt:ialog );

    if( parent == NULL )
    { basewin->setGeometry( QRect( BW_TOP, BW_LEFT, BW_BOTTOM - BW_TOP, BW_RIGHT - BW_LEFT ) ); }
    else
    {
    // Set relative to the container
    //
    newrct.setTop( 0 );
    newrct.setHeight( BW_BOTTOM - BW_TOP );
    newrct.setLeft( 0 );
    newrct.setWidth( BW_RIGHT - BW_LEFT );

    basewin->setGeometry( newrct );
    basewin->move( QPoint( qrct.left() + 20, qrct.top() + 20 ) );
    }

    QProgressBar *mybar = new QProgressBar( basewin );
    mybar->setGeometry( QRect( 10, 30, (BW_RIGHT - BW_LEFT), 25 ) );

    basewin->show();
    }

    If I comment out the basewin->show() in the constructor and enable the pb.show() as below in the application test, the widget doesn't display.
    void TestRig::TestProgress( void )
    {
    ProgressBar pb( this );

    pb.SetWindowTitle( "Progress bar title" );
    // pb.show();

    xvt_dm_post_note( "Test Progress: Any Key To Continue" );
    }

    What am I missing here. Should not the pb.show() in the application cause the widget to display.
    The reason I need this behavior is that there are other items that have to be setup before the pb widget is displayed. Other controls may or may not be inserted and the geometry needs to be adjusted prior to the actual display.

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Operation of 'show'

    It will cause the empty ProgressBar QWidget to display. The other widgets you create in the ProgressBar constructor are not put in a layout and do not automatically inherit visibility as a result. See: [doc=layout.html]Layout Management[/doc]

    It's not immediately apparent what effect you are trying to achieve but the way you are going about it is irregular.

  3. #3
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Operation of 'show'

    I don't quite understand what you are saying. In the TestProgress method, the base screen widget and the QProgressBar have been created. The base dialog window doesn't show up when show is called from outside the constructor. If just the QProgress bar didn't show up I could figure that but in fact nothing shows up. I looked at the layout management doc and in glancing at it, it doesn't appear to address what I need or the question of why show doesn't work from the outside.

    This is a copy of an element that I wrote years ago in a different GUI system. The current product is being converted to Qt and this widget needs three QProgress bars, a QTextEdit, and several QLabels, and a QButton. Some or none of the extra elements may be displayed (and the geometry modified accordingly). What is displayed depends on the needs of the function calling it.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Operation of 'show'

    The thing you are calling show() on is the the QWidget-derived ProgressBar object: and it will be shown. That object has created a few other objects that it owns (a generic QDialog and QProgressBar) but as it never puts them in a layout in its client area or explicitly show()s them these objects have no visible manifestation. Ownership does not equal visibility.

    What you want is more like this:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ProgressDialog: public QDialog
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit ProgressDialog(QWidget *p = 0): QDialog(p) {
    8. QLabel *label = new QLabel("A Label", this);
    9. QTextEdit *edit = new QTextEdit(this);
    10. QProgressBar *pb1 = new QProgressBar(this);
    11. pb1->setValue(10);
    12. QProgressBar *pb2 = new QProgressBar(this);
    13. pb2->setValue(50);
    14. QProgressBar *pb3 = new QProgressBar(this);
    15. pb3->setValue(90);
    16. bb->addButton(QDialogButtonBox::Cancel);
    17. bb->addButton(QDialogButtonBox::Ok);
    18. connect(bb, SIGNAL(rejected()), SLOT(reject()));
    19. connect(bb, SIGNAL(accepted()), SLOT(accept()));
    20.  
    21. QVBoxLayout *layout = new QVBoxLayout(this);
    22. layout->addWidget(label);
    23. layout->addWidget(edit);
    24. layout->addWidget(pb1);
    25. layout->addWidget(pb2);
    26. layout->addWidget(pb3);
    27. layout->addWidget(bb);
    28. }
    29. };
    30.  
    31. int main(int argc, char **argv)
    32. {
    33. QApplication app(argc, argv);
    34.  
    35. ProgressDialog pb;
    36. pb.show();
    37. return app.exec();
    38. }
    39. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    sterling (9th January 2014)

  6. #5
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Operation of 'show'

    Thanks. Most important was understanding what was happening, whether or not it was the 'right way' was of secondary importance. FYI, I created a virtual void show( void ) in the class and when show was called from the outside, it did what I expected it to do in the first place.

    I will look at the example to understand what you did and its ramifications with respect to what I am trying to do. If there was any name confusion, I need to keep the class name the same to avoid having to change the source code in the older GUI.

    Thanks

Similar Threads

  1. Replies: 6
    Last Post: 12th September 2011, 12:23
  2. Replies: 10
    Last Post: 16th March 2010, 08:50
  3. How show progress of slow a operation?
    By shud in forum Qt Programming
    Replies: 9
    Last Post: 3rd December 2009, 22:10
  4. Show progress of a time consuming operation
    By rainman110 in forum Newbie
    Replies: 7
    Last Post: 10th February 2008, 12:07
  5. Problem in Cut Operation
    By ankurjain in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2006, 12:23

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.