To build a gallery of images, I need an infinite layout, similar to Grid, but items have fixed height and variable width, something like the image below, I tried Grid and flutter_staggered_grid_view, but non is suitable. I tried Wrap in a SingleChildScrollView, but it's not virtual list and renders all items initially, so it's slow:
Related
I need to create multiple charts, where the graph area is exactly the same height (but other chart element heights can vary).
What kind of method could be used to achieve this functionality?
By default Chart.js aims to fill the canvas height when drawing elements which makes the graph area height dependent on the canvas height and other chart elements like the title height and legend height.
This problem has been discussed on Chart.js GitHub (https://github.com/chartjs/Chart.js/issues/3458), the devs seem to agree that this fuctionality should be handled by a custom plugin and not by the core library anyway.
I'm a bit lost. So far I've tried to modify the y-scale height, maxHeight, padding, margin etc. in beforeFit and afterFit -hooks, but those don't seem to do anything. I just don't seem to grasp how the height setting is handled in the source code and how to go about overriding it.
I am using tableview to display a list of items
e.g.
list =
[
{name='bob',
description='really long description that can be multiple rows',
image='an image from my server',
},
...
]
the above is just an example. I got my data from my server, including images of variable sizes. My question is how do I display the correct row size(height) once I got image from the server. I understand that I can wait until all data and image has been downloaded from server. Then precompute the height. But I want to be able to display the text first (as texts are more likely to be firstly downloaded), then once there is an image in it, I download it again. After the image is downloaded, I want to resize the row height. How can I do that?
Create a multi-line display.newText() of the width you expect to put in the table view. When the object is created, grab it's height and then remove the object. Use that height + some padding for the row height. There may be performance issues with this, so as an alternate, keep the text object and pass it in as a parameter when you create the row.
I'm having trouble with Qt.
I'm writing an app that takes a PNG file from database, and allows you to apply multiple layers (each representing a different set of multiple-choice elements (also from database) for different areas of the base PNG), and displays the result within QGraphicsView Widget. However, when I merge the original image with an element, the original gets smaller and gets a "border" around it.
Examples:
Original image - http://i.imgur.com/6kI2M2y.png (sans black area)
The black element is another PNG, in which there's the element and it's surrounded by transparency.
Result after few merges - http://i.imgur.com/wx8UmmK.png
What the hell? The QGraphicsView is 520x520 and doesn't touch any other Widget. I have to get the app to be able to merge the contents of QGraphicsView multiple times without any kind of movement/resizing, as there will be lots and lots of undecided clicking between various elements and layers.
The app works like this: I have two dynamicly generated arrays of buttons with images taken from database, let's say the Base list and Elements list. When I click a button in the Base list, it's loaded into the main QGraphicsView. Now I am supposed to be able to add elements onto that loaded image by clicking buttons on the other list. I do that by getting the content of QGraphicsView widget and drawing the element using a QPainter.
void MainWindow::on_pushButton_clicked() //placeholder for merging testing
{
QPixmap element("C:\\Users\\Petersaber\\Desktop\\warstwa1.png");
QPixmap base = QPixmap::grabWidget(ui->QGraphicsView);
base= oryginal.scaled(QSize(520,520),Qt::KeepAspectRatio, Qt::SmoothTransformation); //resized to QGV
element= element.scaled(QSize(520,520),Qt::KeepAspectRatio, Qt::SmoothTransformation); //resized for QGV
QPainter painter(&base);
painter.drawPixmap(0,0,element);
//the error happens somewhere later from this point
QGraphicsScene* sceneElement = new QGraphicsScene();
QGraphicsPixmapItem* dodany = new QGraphicsPixmapItem(base);
sceneElement->addItem(dodany);
ui->QGraphicsView->setScene(sceneElement);
ui->QGraphicsView->fitInView(sceneElement->sceneRect(),Qt::KeepAspectRatio);
ui->QGraphicsView->show();
}
My guess is that for some reason it takes more than just what's INSIDE of the QGraphicsView, it also takes the 1-2 pixels around it, but why? How to prevent that? I have no idea. I'm a total newbie to Qt, I've only started two days ago.
edit: I am wrong. That's not how it works. The error happens AFTER the merging. Wtf?
It happens regardless of what size the merged images are. After every merge, two white pixels and 1px border always appear between the merged image and the QGraphicsView edge.
edit: I've discovered that the 2px margin is hard-coded into QGraphicsView::fitInView(). I have no idea how to work around that. I've found pieces of code, such as this,
QRectF removeMargin11945(const QRectF& sceneRect, const QSize& viewerSize){
const int bugMargin = 2;
const double mx = sceneRect.width()/viewerSize.width()*bugMargin;
const double my = sceneRect.height()/viewerSize.height()*bugMargin;
return sceneRect.adjusted(mx, my, -mx, -my);
}
, but I don't know how to implement that
I'm new to Qt development so I've being trying to research a solution to a user interface I need to design. My project is to simulate players in an online game moving around a global map. To represent the map I need to display a 2D grid, with each space in the grid representing a region of a map. I then need to display the location of each player in the game. The back-end is all fully working, with the map implemented as a 2D array. I'm just stuck on how to display the grid.
The research I have done has led me to believe a QGraphicsView is the best way to do this, but I can't seem to find a tutorial relevant to what I need. If anyone has any tips on how to implement this it would be much appreciated.
Thanks, Dan
A 2D Grid is nothing more than a set of horizontal and vertical lines. Suppose you have a 500x500 map and you want to draw a grid where the distance between the lines in both directions is 50. The sample code that follows shows you how you can achieve it.
// create a scene and add it your view
QGraphicsScene* scene = new QGraphicsScene;
ui->view->setScene(scene);
// Add the vertical lines first, paint them red
for (int x=0; x<=500; x+=50)
scene->addLine(x,0,x,500, QPen(Qt::red));
// Now add the horizontal lines, paint them green
for (int y=0; y<=500; y+=50)
scene->addLine(0,y,500,y, QPen(Qt::green));
// Fit the view in the scene's bounding rect
ui->view->fitInView(scene->itemsVBoundingRect());
You should check the QGraphicsView and the QGraphicsScene documentation as well as the corresponding examples. Also you can watch the graphics view training videos or some graphics view related videos from the Qt developer days.
Well if you have a constant grid size or even a limited number of grid sizes what i like to do is to draw a grid block in gimp or any other program and then set that as the background brush (draw only bottom and right side of the block) qt will repeat the image and will give you a full grid. I think this is good for performance too.
This is the grid image i used in one of my programs it's 10x10 pixels.
Then call QGraphicsScene setBackgroundBrush as the follwing:
scene->setBackgroundBrush(QBrush(QPixmap(":/grid/grid10.png")));
The more native way is this:
scene = self.getScene() # Your scene.
brush = QBrush()
brush.setColor(QColor('#999'))
brush.setStyle(Qt.CrossPattern) # Grid pattern.
scene.setBackgroundBrush(brush)
borderColor = Qt.black
fillColor = QColor('#DDD')
rect = QRectF(0.0, 0.0, 1280, 720) # Screen res or whatever.
scene.addRect(rect,borderColor,fillColor) # Rectangle for color.
scene.addRect(rect,borderColor,brush) # Rectangle for grid.
Sorry by PyQt...
Suppose a scene is set to the graphicsview then simply below one line will show the grid.
ui->graphicsView->scene()->setBackgroundBrush(Qt::CrossPattern);
There several other values can be passed for ex: Qt::Dense7Pattern
These are members of enum BrushStyle, just click on any used value in Qt creator and it will take you to the enum declaration where you can see all other possible values.
PS:
A scene can be set like this:
ui->graphicsView->setScene(new QGraphicsScene());
i need to add in list components that are not equal in height, is there a way for it to work?
Different cell heights within a list are not supported by LWUIT. The list takes care and resizes all cells to the size of the largest one.
Thought about different renderers (e.g. fisheye renderer link) for different components if you need to alter , even thought the cell height stays the same for the whole list.
Use the ContainerList class which is a part of LWUIT 1.5 and Codename One.
You can use your component which extends from container and add those components in a Container which has BoxLayout.Y axis as its layout so that all the list items will have height according to the text that you added. How many items do you want to add?