[Interest] Adding button groups to toolbars?

André Somers andre at familiesomers.nl
Tue May 29 13:11:19 CEST 2012


Op 29-5-2012 12:09, Sensei schreef:
> Hi everyone,
>
> I have (another) problem. I am trying to mimick the layout of Xcode,
> making a simple custom widget with a toolbar on top and a widget on the
> bottom.
>
> I was able to create a vertical layout and add a series of actions,
> adding them to the toolbar. Now I was moving to the next level: adding a
> QButtonGroup with mutually exclusive buttons.
>
> What's the best way to do this? I can't add a QButtonGroup to a toolbar,
> and I can't add a QButtonGroup to a vertical layout. So far, that's what
> I've tried, but I can't figure it out.
>
> Can you give me a hint?
Try adding QAction objects to your toolbar instead, and group these 
actions in a QActionGroup to make them exclusive.

André

> Thanks?
>
>
>       // Main working area
>       area_ = new QSplitter(this);
>
>       // Custom widget
>       QWidget *w = new QWidget(this);
>       // Vertical stack
>       QVBoxLayout *box = new QVBoxLayout(w);
>       // Toolbar
>       //QToolBar *tb = new QToolBar(w);
>       // Button group
>       QButtonGroup *bg = new QButtonGroup(area_);
>       // Buttons
>       QPushButton *b1 = new QPushButton("Hello");
>       QPushButton *b2 = new QPushButton("This");
>       QPushButton *b3 = new QPushButton("World");
>       b1->setChecked(true);
>       bg->addButton(b1);
>       bg->addButton(b2);
>       bg->addButton(b3);
>       bg->setExclusive(true);
>       //tb->addWidget(dynamic_cast<QWidget*>(bg) );
>       // Main view
>       QTextEdit *w1 = new QTextEdit(area_);
>       // Add to vbox
>       box->addWidget(bg);
>       box->addWidget(w1);
>       // Set the widget layout to vbox
>       w->setLayout(box);
>
>       QTextEdit *w2 = new QTextEdit(area_);
>
>       area_->addWidget(w);
>       area_->addWidget(w2);
>
>       // Set the layout
>       setCentralWidget(area_);
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest




More information about the Interest mailing list