Tab text alignment in QTabWidget - qt

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()});

Related

Placing buttons on opposite sides of an adjustable window in JavaFX

I have two buttons that I'd like to use in my display screen: a reset button, and a settings button.
The problem is, I want them on opposite sides of the window (reset in the top right corner and settings in the top left) while being the same height. When I expand the window, however, the buttons stay in the same place, but I want them to move with the window walls.
I first tried using setAlignment of my reset button to Pos.*TOP_RIGHT* and the settings button to top left, but it comes out with the settings button being on top of the reset button.
resetButton = new Button("Reset Gameboard");this.setTop(resetButton);
resetBox = new HBox(resetButton);
resetBox.setAlignment(Pos.TOP_RIGHT);
backButton = new Button("Back to Settings");
this.setTop(backButton);
backBox = new HBox(backButton);
backBox.setAlignment(Pos.TOP_LEFT);
resetbackBox = new HBox(backButton, resetButton);
this.setTop(resetbackBox);`
I currently am using (below) which during the initial window appears to be working and correctly spaced, but as soon as you expand the window the reset button doesn't follow it, although the settings button does.
`resetButton = new Button("Reset Gameboard");
this.setTop(resetButton);
resetBox = new HBox(resetButton);
resetBox.setAlignment(Pos.TOP_RIGHT);
backButton = new Button("Back to Settings");
this.setTop(backButton);
backBox = new HBox(backButton);
backBox.setAlignment(Pos.TOP_LEFT);
resetbackBox = new HBox(backButton, resetButton);
resetbackBox.setSpacing(380);
this.setTop(resetbackBox);`
The problem start from this line:
resetbackBox.setSpacing(380);
You have setted a fixed spacing value. To fix that you can easily add a component to HBox called Region, this component allow to set a grow area between two buttons:
Button resetButton = new Button("Reset Gameboard");
Button backButton = new Button("Back to Settings");
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HBox topHBox = new HBox(backButton, region, resetButton);
this.setTop(resetbackBox);

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.

How to add widgets to QToolbox item

I need to auto generate some UI forms in code to display message contents.
I want to use QToolbox, with an item for each message type. I then want to add labels and line edit to the contents of each tab, depending on the message protocol. I cannot seem to programaticaly add widget items to the toolbox item.
Below is my current code segment. The ui->frame is just a container for the toolbox. I will worry later about layout.
In my code, I create a frame and then some labels with parent set to the frame. Then I add the frame as an item to the toolbox.
QToolBox *qtbMainToolbox = new QToolBox(ui->frame);;
qtbMainToolbox->setGeometry(0,0,2000,900);
QFrame *frm1 = new QFrame;
QLabel *lbl1 = new QLabel(frm1);
QLabel *lbl2 = new QLabel(frm1);
QLabel *lbl3 = new QLabel(frm1);
QLabel *lbl4 = new QLabel(frm1);
iRetVal - qtbMainToolbox->addItem(frm1 ,"Test");
There is no visible element in your widgets; icon or any text.
You have to Set icon or Text to Your QLabel.
QToolBox *qtbMainToolbox = new QToolBox(ui->frame);;
qtbMainToolbox->setGeometry(0,0,2000,900);
QFrame *frm1 = new QFrame;
QLabel *lbl1 = new QLabel("Hello World",frm1);
iRetVal - qtbMainToolbox->addItem(frm1 ,"Test");
try above code.

QTreeWidget - width of column with widget

I have QTreeWidget with two columns. The first column is the text, and the second is QPushButton. I can not specify the size of buttons and the size of the second column. When you try to set the size of the column of content, the second column disappears. How to change the width of the second column?
tree_widget_->setColumnCount(2);
tree_widget_->header()->resizeSection(1, 10);
tree_widget_->header()->setStretchLastSection(false);
tree_widget_->header()->setResizeMode(0,QHeaderView::Stretch);
tree_widget_->topLevelItem(4)->addChild( wiop = new QTreeWidgetItem(QStringList() << QString( "Расстояние: %1 км" ).arg( range ) ) );
tree_widget_->setItemWidget(tree_widget_->topLevelItem(4)->child(0),1,range_plot_button_ = new QPushButton("График",tree_widget_));
range_plot_button_->resize(10,10);
tree_widget_->setColumnWidth(1, 10) should do what you wanted.
When you assign QPushButton to QTreeWidget as a top level item the QTreeWidget object usualy assigned as a parent of this button, so all geometry of that button is handled by it's parent.
Take a look at docs.
If you want your push button to have it's own geometry with layouts (within column) you can make blank widget, set it to TreeWidget as an item and make your push button to be a child of that blank widget with all conveniences of layouts in Qt.
I try setColumnWidth, but it is not work.
Later I try tree_widget_->header()->setResizeMode(1,QHeaderView::ResizeToContents);
and it is work!

how to layout the button item on ribbon pagegroup with the style like the picture

the large glyph all on the left . small glyph on the right with vertical allignment.
all the button are generated on the code.
this is my code using c# for winform showing
RibbonPageGroup pagGroup = new RibbonPageGroup();
BarButtonItem barButtonItem = new BarButtonItem();
pagGroup.ItemLinks.Add(barButtonItem);e
You should add your bar item links into PageGroup one by one. For small items use the BarItemLink.BeginGroup property to separate all the next items into button group:
// ribbonPageGroup1
ribbonPageGroup.ItemLinks.Add(barButtonItem1);
ribbonPageGroup.ItemLinks.Add(barButtonItem2);
ribbonPageGroup.ItemLinks.Add(barButtonItem3, true); // begin group
ribbonPageGroup.ItemLinks.Add(barButtonItem4);
ribbonPageGroup.ItemLinks.Add(barButtonItem4);
Use the BarItem.RibbonStyle propety to specify display options for specific bar items:
barButtonItem3.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.SmallWithText;

Resources