Window Positioning/Refreshing/TableWidget/Json
-
#Question 1 - window position
I have the following code:map::map(QWidget *parent): QWidget(parent), ui(new Ui::map) { if (opened == false){ MapToolbar *MapTool = new MapToolbar(); MapTool->show(); opened = true; } ui->setupUi(this); }
Now, as u can see, I open 2 window at the same time which resultst the following: MapToolbar widget opens and after that, Map widget opens as well, so it hides the first window (I have to drag the last window to see the first one). Is there any way to calibrate the opening window's location on the screen? My goal is to display 2 windows next to each other and not behind each other.
#Question 2 - refresh another window
As I mentioned in my first question, I have 2 windows. MapToolBar and MapPlanner. I give the coordinates in MapToolBar and I want it to refresh on the MapPlanner. The current state is the following: I draw a line and it only appears when I CLICK on the MapPlanner window (so it'd be good if I could refresh the other window or make the second window the ACTIVE WINDOW (the one I'm working in)). Picture and description:
The MapPlanner will draw a line with the following coordinates but ONLY if I click INSIDE the MapPlanner (so it only refresh itself if I switch the window). Do u know any solution for that?#Question 3 - refresh another window's TableWidget
There is an option where I can import datas from a .json file. It opens a third window where I can search the map name and import it into the MapToolBar - everything is fine so far. But when I import, it gives the datas to the MapToolBar TableWidget but doesn't show, only if I click on the "Draw (Rajzol)" button (this onClickButton also calls the function I inserted below, and this refreshes the datas instant)... Here is the code that refresh the Table Data:void MapToolbar::refreshDataTable() { ui->coordinateTable->clearContents(); ui->coordinateTable->setRowCount(0); ui->coordinateTable->setRowCount(CoordCounter); for (int i=0; i<CoordCounter; i++) { QString x1_s = QString::number(coords[i].x1); QString x2_s = QString::number(coords[i].x2); QString y1_s = QString::number(coords[i].y1); QString y2_s = QString::number(coords[i].y2); ui->coordinateTable->setItem(i, 0, new QTableWidgetItem(x1_s)); ui->coordinateTable->setItem(i, 1, new QTableWidgetItem(x2_s)); ui->coordinateTable->setItem(i, 2, new QTableWidgetItem(y1_s)); ui->coordinateTable->setItem(i, 3, new QTableWidgetItem(y2_s)); ui->coordinateTable->setItem(i, 4, new QTableWidgetItem(coords[i].color)); } }
I call this function from the 3rd window (import window) and it works, because if I put a qDebug() or anything else inside of it, it appears after the import proccess, only the table widget not updating
#Question 4 - .json write
I have the code and json file (working fine):QJsonArray maps = QJsonDocument::fromJson(val.toUtf8()).array(); QJsonObject obj = data.toObject(); auto mapName = obj["MapName"].toString(); QJsonValue mapCoords = obj["Coords"]; QJsonObject mapCoord = mapCoords.toObject(); QJsonArray mapX1CoordsArray = mapCoord["X1Coords"].toArray(); QJsonArray mapX2CoordsArray = mapCoord["X2Coords"].toArray(); QJsonArray mapY1CoordsArray = mapCoord["Y1Coords"].toArray(); QJsonArray mapY2CoordsArray = mapCoord["Y2Coords"].toArray(); QJsonArray mapColorCoordsArray = mapCoord["Colors"].toArray();
So I can read a json file but how can I write one with code? I mean, I use this for importing map coordinates into my code, but I want another function to export them. I didn't find any useful information for that so that's why I'm asking you. Do u know any solution (taking into consideration my import code)?I know that I'm asking a lot, I'm just kinda new in QT and want to learn from straight answers (I'm searching on the Internet a lot and I only ask you if I don't find an answer after hours of searching). Thank u in advance!
-
Hi,
Are you providing an API that allows to propagate your updates to the corresponding widgets ?
#4 : QJsonDocument::toJson with QFile::write