I have two QTableViews (one nested within the other) that share one selection model:
void MyTableWidget::setSelectionModel( QItemSelectionModel* in_p_selection_model )
{
QTableView::setSelectionModel( in_p_selection_model );
m_p_inner_tableview->setSelectionModel( in_p_selection_model );
}
The first QTableView should not automatically scroll to the selected item when I make a selection in the second QTableView. As far as I can tell, there is no "auto scroll to selection" flag. So how can I prohibit this behavior?
Related
I'm trying to remove the down arrow from a combobox. All the solutions I have found just make the arrow disappear, for example this one.
Is there a way to remove completely the space where the arrow appears and fill the box just with the text of the selected choice?
If you want to completely elimnate the arrow & arrow button space, you can try with the below custom ComboBox.
The below code is setting the arrow button and arrow nodes size to 0 and asking to rerender the comboBox. The null check is to let this changes apply only once.
public class MyComboBox<T> extends ComboBox<T>{
Region arrowBtn ;
#Override
protected void layoutChildren() {
super.layoutChildren();
if(arrowBtn==null){
arrowBtn= (Region)lookup(".arrow-button");
arrowBtn.setMaxSize(0,0);
arrowBtn.setMinSize(0,0);
arrowBtn.setPadding(new Insets(0));
Region arrow= (Region)lookup(".arrow");
arrow.setMaxSize(0,0);
arrow.setMinSize(0,0);
arrow.setPadding(new Insets(0));
// Call again the super method to relayout with the new bounds.
super.layoutChildren();
}
}
}
UPDATE :
Based on the suggestion of #kleopatra, we can get the same behaviour using css as well (without the need to create a new class for ComboBox).
.combo-box .arrow-button,
.combo-box .arrow{
-fx-max-width:0px;
-fx-min-width:0px;
-fx-padding:0px;
}
The below image will tell you the difference of a normal combox box and this custom combo box. The left one is the normal comboBox, you can see the list cell when inspecting with ScenicView. The right one is the custom one. The list cell is completely occupied suppressing the arrow space.
I am using the QtQuick's Drag and Drop example (the Tiles part) to drag and drop tiles (representing buttons) from the list onto the grid as a way to dynamically lay out these buttons.
When "removing" (i.e. reparenting) the tile from the list, an empty space is left. I would like the list to automatically reorganize to close this gap. Is that possible using the approach in the example where the drag/drop is simply done by reparenting the tile? Or do I need to have two models (one for the list and one for the grid) and add/remove the dragged item between the two models?
Thanks for your help!
See this image
to get a better idea of what I mean.
It happens because in the example they just apply a parent change on a child of the tile, so the empty root Item remains in the columns:
// DragTile.qml
Item {
id: root
// ...
MouseArea {
// ...
drag.target: tile
onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root
Rectangle {
id: tile
// ...
}
}
}
If you apply the parent change to the root Item, the Column will automatically be reorganized:
onReleased: {
if (tile.Drag.target) {
root.parent = tile.Drag.target
root.anchors.centerIn = root.parent
}
}
When I start a page with grid, first row is focused and this style is beeing applied(row is highlighted):
.v-grid-row-focused > .v-grid-cell {
// ...
}
But when I programmtically change data source
grid.setContainerDataSource(...)
It doesn't highligh first row.
I've tried to select and deselect first item but it doesn't work.
myGrid.focus() also doesn't work.
How can I do that programmatically?
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!
I have several QGraphicItems in a QGraphicsScene.
I want to modify only some of them when the QGraphicsView containing the scene gets resized.
The reason is that I have painted a grid respective to the view.
So how can I identify the items making up the grid in a QGraphivcsView::resizeEvent()?
Would it be possible to adjust the scene in a way that a given area (sceneRect) is always filling the complete view?
So how can I identify the items making up the grid in a QGraphivcsView::resizeEvent()?
One way would be to simply use dynamic_cast and QGrahpicsScene::items():
foreach( QGraphicsItem *item, myScene->items() )
{
GridItem *gridItem = dynamic_cast<GridItem*>( item );
if( gridItem )
{
// Apply appropriate transformation here
}
}
A slightly more "Qt" way to do the above would be to ensure your QGraphicsItem subclass reimplements QGraphicsItem::type()
foreach( QGraphicsItem *item, myScene->items() )
{
if( item->type() == GridItem::Type )
{
// Apply appropriate transformation here
}
}
Would it be possible to adjust the scene in a way that a given area
(sceneRect) is always filling the complete view?
QGraphicsView::fitInView() should do the trick
Also, while I'm not entirely sure what you're trying to accomplish, it sounds to me that you may want to check out the QGraphicsItem::ItemIgnoresTransformations flag.
myItem->setFlag( QGraphicsItem::ItemIgnoresTransformations )
which makes it so that any item with the given flag will not be affected by changes in the zoom level.