Slider invisible in vaadin - vaadin7

I am using a Vaadin Slider in a gridLayout but the slider is invisible, only the caption is there. This is my code:
GridLayout gridField = new GridLayout(2, 3);
gridField.setWidth(100.0f, Unit.PERCENTAGE);
gridField.setSpacing(true);
Slider slider=new Slider("name " ,0,100);
slider.setWidth(100.0f, Unit.PERCENTAGE);slider.setImmediate(true);
gridField.addComponent(slider);
Have you any idea please?

Related

How do you place a groupbox in a QMenuBar?

I need the groupbox that contains the ID picture and a button on the right side of the QMenuBar, and I don't know how to do that. Here's what I have so far:
QGridLayout *menulayout = new QGridLayout();
QWidget *menuwidget = new QWidget (dynamic_cast<QMainWindow*>(this->parent())->menuBar());
menulayout->setContentsMargins(18,0,18,0);
menulayout->addWidget(menuwidget);
menulayout->addWidget(_ui->groupBox_UserMenu, 0 ,0);
dynamic_cast<QMainWindow*>(this->parent())->menuBar()->setLayout(menulayout);
Fixed this by placing the groupbox on the desired position on the Form and then set it's parent to the QMenu Bar. The first lines of code I posted were unnecessary.
_ui->groupBox_UserMenu->setParent(_ui->menuBar);

How to set a center aligned QLabel to toolbar in Qt

I'm new to qt and exploring it .I want to have a text which is center aligned in my Mainwindow's toolbar.Below is my code inside my MainWindow constructor:
QLabel* label=new QLabel("Hello World");
label->setAlignment(Qt::AlignHCenter);
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(label);
QWidget* wid = new QWidget;
wid->setLayout(layout);
ui->mainToolBar->addWidget(wid);
The above code displays the text , but not at the center.It displays at the left.What am I missing?Any help will be really helpful.
label->setAlignment(Qt::AlignHCenter);
This tells the label to (horizontally) center the text in itself.
layout->addWidget(label);
This is expanded by default argument to
layout->addWidget(label, 0);
Where the 0 is the stretch factor of the label within this layout. Zero means your label will be given as much space as it needs to display properly but nothing more. So your label is just as big as your text needs, has it's text centered, but since it's on a QHBoxLayout it's shown on the left side within your bar. If there are no other widgets in your bar's layout, you can set the stretch-factor to 1 to make the label fill the layout, your text will then show in the center.
layout->addWidget(label, 1);

Qt tab widget add corner group widget

I want to add a group widget to the corner of tab widget. so i wrote these below, but doesn't work.
auto layout = new QHBoxLayout;
auto text = new QTextEdit;
auto button = new QPushButton("find");
layout->addWidget(text);
layout->addWidget(button);
auto group = new QGroupBox;
group->setLayout(layout);
stageTabWidget->setCornerWidget(group);
problem solved! It turns out that the group was too small to show the widget. Change the style of the group with this line group->setStyleSheet("QGroupBox{border:0px;padding-top:-10px;padding-bottom:-10px;}"); will be ok.

Tab text alignment in QTabWidget

I am using QTabWidget class of Qt.
In TabWidget i am dynamically adding new tab and setting the TextElideMode to right to display the toolbutton in tabBar.
tabWidget = new QTabWidget(this);
m_addNewTab = new QWidget(tabWidget);
m_addNewGridLayout = new QGridLayout(m_addNewTab);
m_addNewWebView = new MyWebView(m_addNewTab);
widget = new QWidget(m_addNewTab);
tb = new QToolButton(widget);
tb->setFixedHeight(20);
tb->setText("<");
tb1 = new QToolButton(widget);
tb1->setFixedHeight(20);
tb1->setText(">");
m_horizontalLayout = new QHBoxLayout(widget);
m_horizontalLayout->addWidget(tb);
m_horizontalLayout->addWidget(tb1);
Please see the below screen shot for the output of the sample application.
When the current tab is selected then both the toolbutton should display and text elide mode should be right but when tab is not selected then toolbutton should not be displayed but text elide mode should be left.
Here in below screen shot i am able to hide and show the toolbutton depending on tab selection but when the tab is not selected text elide mode is setting as right so we are able to see the unnecessary space (check last tab). Setting the text elide mode left also not working because we have already set the toolbutton at left side.
Can someone guide me how to remove the space (last tab from screen shot) when there is not tab selected ?
You'll have to:
Keep track of tab index and corresponding holding widget (let's say std::map<int,QToolButton> toolbutton_by_index
When QTabWidget.currentChanged is emitted, deactivate all widgets except the selected
You can do the 2nd part like this:
std::for_each(toolbutton_by_index.begin(), toolbutton_by_index.end(),
[&index](auto pair){
(pair.first == index)?pair.second->hide():pair.second->show()});

How to add a scrollbar to parent QWidget

I understand how to add a scrollArea to a particular widget. However in my case Qwidget has multiple child widgets and these are all set using QVBoxLayout. Now how can I add a scroll bar in this case? Here QWidget is not the center widget, its one of the pages of the TabWidget. My code looks like:
QTabWIdget *center = new QTabWidget; setCentralWIdget(center);
xTab = new QWidget;
formLayout = new QFormLayout; formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...);
xTab->setLayout(formLayout);
Now how can I set the scrollBar to xTab? I tried using
scrollArea = new QScrollArea;
scrollArea->setWidget(xTab);
however, this isn't working.
Any idea/suggestions are helpful and appreciated.
Have you tried using QScrollArea as the tab page?
QTabWIdget *center = new QTabWidget; setCentralWIdget(center);
xTab = new QScrollArea;
formLayout = new QFormLayout; formLay....
xTab->setLayout(formLayout);
center->addTab(xTab, "XXX Tab");
I had success using the following:
scroll=new QScrollArea(mainWindow->centralWidget);
scroll->setGeometry(mainWindow->tabWidget->geometry());
scroll->setWidget(mainWindow->tabWidget);
scroll->show();
The QScrollArea defines where the scrollable widget will appear. If parent is 0, it's a non-modal window. setGeometry sets the QScrollArea instance to the desired dimensions (that of the tab). setWidget defines what widget the QScrollArea will actually be scrolling.

Resources