Results 1 to 5 of 5

Thread: Adding qframe with widgets to status bar

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

    Default Adding qframe with widgets to status bar

    Hi,

    I have following problem:
    I would like to add to status bar custom widgets (mainly qlabels) with setFrameStyle setup. At the rigth corner there should be checkbox + progress bar which have also frame but both of them. I try it this way (just for testing) but widgets (btn and btn1) aren't displayed. There exist some way how to do this cleanly?

    Qt Code:
    1. QLabel *lbl = new QLabel("Label");
    2. lbl->setFrameStyle(QFrame::Sunken | QFrame::Box);
    3. ui->statusBar->addWidget(lbl);
    4.  
    5.  
    6. QFrame *frame = new QFrame();
    7. frame->setFrameStyle(QFrame::Sunken | QFrame::Box);
    8. frame->setGeometry(50,-2,100,15);
    9.  
    10. QPushButton *btn = new QPushButton(frame);
    11. btn->setText("This is button");
    12.  
    13. QPushButton *btn1 = new QPushButton(frame);
    14. btn1->setText("This is button 1");
    To copy to clipboard, switch view to plain text mode 

    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: Adding qframe with widgets to status bar

    Your code is not reflecting what you described you want.
    You only added a QLabel to your statubar, the frame and buttons are not added to it.
    You should add:
    Qt Code:
    1. ui->statusBar->addWidget(frame);
    To copy to clipboard, switch view to plain text mode 
    ==========================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: Adding qframe with widgets to status bar

    Hi,

    you re right I forgot to copy last line of my code. But despite of that it's not working. See preview.
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding qframe with widgets to status bar

    You need to set a layout to frame.. and add the label / push button to the layout.
    Simply making the frame parent of widgets will show those widgets at position (0,0).

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

    binaural (28th May 2010)

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

    Default Re: Adding qframe with widgets to status bar

    Thanks,

    works perfectly in that way:
    Qt Code:
    1. QFrame *status_frame = new QFrame();
    2. status_frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    3.  
    4. QHBoxLayout *layout = new QHBoxLayout(status_frame);
    5. layout->setContentsMargins(0, 0, 0, 0);
    6. QProgressBar *bar = new QProgressBar(status_frame);
    7. bar->setMaximumHeight(10);
    8. bar->setMaximumWidth(100);
    9.  
    10.  
    11. QCheckBox *box = new QCheckBox(tr("Check Mode"), status_frame);
    12. box->setChecked(true);
    13.  
    14. layout->addWidget(bar);
    15. layout->addWidget(box);
    16. ui->statusBar->insertWidget(5, status_frame);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 5
    Last Post: 18th April 2010, 23:31
  2. Adding more tab widgets
    By rakkar in forum Newbie
    Replies: 2
    Last Post: 10th September 2009, 21:22
  3. Adding widgets dynamically
    By miw in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2009, 10:31
  4. adding and removing widgets
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 30th November 2007, 01:34
  5. QFrame showing 4 different widgets
    By hgedek in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 17:29

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.