How to simplify syntax
-
I have Window.ui which has predefined QLabel as follow:
QLabel QLabel QLabel QLabel
...
-=- same till ned of QLabel
Each line contains two QLabels to hold txt, two labels to hold Img
I need to simply if some how as it feels very premature
Kindly advise -
I have Window.ui which has predefined QLabel as follow:
QLabel QLabel QLabel QLabel
...
-=- same till ned of QLabel
Each line contains two QLabels to hold txt, two labels to hold Img
I need to simply if some how as it feels very premature
Kindly advise@JacobNovitsky Why do you care how the generated code looks like (I assume you're talking about the code generated from the ui file, if not please formulate the post better, it is hard to understand)?
-
I have Window.ui which has predefined QLabel as follow:
QLabel QLabel QLabel QLabel
...
-=- same till ned of QLabel
Each line contains two QLabels to hold txt, two labels to hold Img
I need to simply if some how as it feels very premature
Kindly advise@JacobNovitsky
If you are talking about the generated code as @jsulm asks then you cannot alter that (other than rewritinguic) and you should not care.If you mean something more like "I have "composite" widgets which contain a text label and an image label, I want to use them multiple times and I would like to reduce/rationalise the code for re-use" then you might create a widget containing the pairs or whatever of sub-widgets and then use Creator/Designer's Promotion facility to create a single widget out of them which can be re-used at design time.
-
I need something like this
for (int i = 0; i < 10; ++i) { // Adjust the number of rows based on your needs QLabel* textLabel1 = new QLabel(QString("Text %1").arg(i * 2 + 1), this); QLabel* imgLabel1 = new QLabel(this); // Image label imgLabel1->setText("Image Placeholder"); // Placeholder text QLabel* textLabel2 = new QLabel(QString("Text %1").arg(i * 2 + 2), this); QLabel* imgLabel2 = new QLabel(this); // Image label imgLabel2->setText("Image Placeholder"); // Placeholder text // Add them to the grid layout layout->addWidget(textLabel1, i, 0); layout->addWidget(imgLabel1, i, 1); layout->addWidget(textLabel2, i, 2); layout->addWidget(imgLabel2, i, 3); -
I need something like this
for (int i = 0; i < 10; ++i) { // Adjust the number of rows based on your needs QLabel* textLabel1 = new QLabel(QString("Text %1").arg(i * 2 + 1), this); QLabel* imgLabel1 = new QLabel(this); // Image label imgLabel1->setText("Image Placeholder"); // Placeholder text QLabel* textLabel2 = new QLabel(QString("Text %1").arg(i * 2 + 2), this); QLabel* imgLabel2 = new QLabel(this); // Image label imgLabel2->setText("Image Placeholder"); // Placeholder text // Add them to the grid layout layout->addWidget(textLabel1, i, 0); layout->addWidget(imgLabel1, i, 1); layout->addWidget(textLabel2, i, 2); layout->addWidget(imgLabel2, i, 3);@JacobNovitsky
So now you want to create widgets dynamically instead of fixed as in the designed.uifile, which we would not have known. OK, so what is the problem/question? Yes you can create widgets dynamically, and put them into say aQGridLayout.Please use the forum's Code tags (
</>button) when pasting blocks of code, it makes it easier for people to read and answer. -
I need something like this
for (int i = 0; i < 10; ++i) { // Adjust the number of rows based on your needs QLabel* textLabel1 = new QLabel(QString("Text %1").arg(i * 2 + 1), this); QLabel* imgLabel1 = new QLabel(this); // Image label imgLabel1->setText("Image Placeholder"); // Placeholder text QLabel* textLabel2 = new QLabel(QString("Text %1").arg(i * 2 + 2), this); QLabel* imgLabel2 = new QLabel(this); // Image label imgLabel2->setText("Image Placeholder"); // Placeholder text // Add them to the grid layout layout->addWidget(textLabel1, i, 0); layout->addWidget(imgLabel1, i, 1); layout->addWidget(textLabel2, i, 2); layout->addWidget(imgLabel2, i, 3);@JacobNovitsky said in How to simplify syntax:
I need something like this
Then write it. What is the problem?
-
That walks like a table, quacks like a table and swims like a table. Are you sure you don't actually want to just use
QTableWidget(orQTableView+ model if you want to be fancy)?@VRonin You're a devil in disguise!
Yes, I'm going to try tableView -
@VRonin You're a devil in disguise!
Yes, I'm going to try tableViewIt looks fine, now I need to find a way to get indices for selected columns
any advise? -
It looks fine, now I need to find a way to get indices for selected columns
any advise? -
tried to post code chunk, but output msg said it was spm
https://justpaste.it/g6kt5above works, but selects all columns together with one click, I need to be able to do it one by one
please advise -
void MyWindow::onSelectionChanged() { // Fetch the currently selected columns using selectedColumns() QItemSelectionModel *selectionModel = tableView->selectionModel(); QModelIndexList selectedColumns = selectionModel->selectedColumns(); // Convert QModelIndexList to a list of column indices QList<int> selectedColumnList; for (const QModelIndex &index : selectedColumns) { selectedColumnList.append(index.column()); } // Sort the list of selected column indices std::sort(selectedColumnList.begin(), selectedColumnList.end()); // Print selected column indices qDebug() << "Selected columns:" << selectedColumnList; }same result
-
void MyWindow::onSelectionChanged() { // Fetch the currently selected columns using selectedColumns() QItemSelectionModel *selectionModel = tableView->selectionModel(); QModelIndexList selectedColumns = selectionModel->selectedColumns(); // Convert QModelIndexList to a list of column indices QList<int> selectedColumnList; for (const QModelIndex &index : selectedColumns) { selectedColumnList.append(index.column()); } // Sort the list of selected column indices std::sort(selectedColumnList.begin(), selectedColumnList.end()); // Print selected column indices qDebug() << "Selected columns:" << selectedColumnList; }same result
@JacobNovitsky said in How to simplify syntax:
same result
so what does
qDebug()atually print there? -
@JacobNovitsky said in How to simplify syntax:
same result
so what does
qDebug()atually print there?@VRonin it prints Selected columns: QList(0)
but I can select only all lines with one click -
@VRonin it prints Selected columns: QList(0)
but I can select only all lines with one click@JacobNovitsky said in How to simplify syntax:
but I can select only all lines with one click
I'm confused, what is the behaviour you would want to happen?
-
Lets say, I selected line 1 3 and 9
or I selected lines 1 2 3
I need to 1) select only 123 out of 9 lines total
2) I need to get selected indices :) -
https://justpaste.it/dwq1c
Above is my last working code, it selects rows line by line as requested,
but outputs
Selected columns: QList()
with no inidicesI believe problem in
QList<int> MyWindow::getSelectedColumns()
Need to clarify/fix this syntax
