PDA

View Full Version : Adding qframe with widgets to status bar



binaural
28th May 2010, 10:07
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? :)



QLabel *lbl = new QLabel("Label");
lbl->setFrameStyle(QFrame::Sunken | QFrame::Box);
ui->statusBar->addWidget(lbl);


QFrame *frame = new QFrame();
frame->setFrameStyle(QFrame::Sunken | QFrame::Box);
frame->setGeometry(50,-2,100,15);

QPushButton *btn = new QPushButton(frame);
btn->setText("This is button");

QPushButton *btn1 = new QPushButton(frame);
btn1->setText("This is button 1");



Thanks

high_flyer
28th May 2010, 10:49
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:

ui->statusBar->addWidget(frame);

binaural
28th May 2010, 11:55
Hi,

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

aamer4yu
28th May 2010, 12:48
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).

binaural
28th May 2010, 14:14
Thanks,

works perfectly in that way:


QFrame *status_frame = new QFrame();
status_frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);

QHBoxLayout *layout = new QHBoxLayout(status_frame);
layout->setContentsMargins(0, 0, 0, 0);
QProgressBar *bar = new QProgressBar(status_frame);
bar->setMaximumHeight(10);
bar->setMaximumWidth(100);


QCheckBox *box = new QCheckBox(tr("Check Mode"), status_frame);
box->setChecked(true);

layout->addWidget(bar);
layout->addWidget(box);
ui->statusBar->insertWidget(5, status_frame);