QLineEdit Matrix, can not select single (QLineEdit) item by clicking



  • Hello all, I have an object that contains some QLineEdit elements.

    My intention is, fill a window with these elements, in the form:
    (0) [..QLineEdit 1..] [..QLineEdit 2..] [..QLineEdit 3..]
    (1) [..QLineEdit 1..] [..QLineEdit 2..] [..QLineEdit 3..]
    (2) [..QLineEdit 1..] [..QLineEdit 2..] [..QLineEdit 3..]
    .
    .
    .
    (19) [..QLineEdit 1..] [..QLineEdit 2..] [..QLineEdit 3..]

    [edited]
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        this->setFixedSize(1333,768);
     [/edited]
        getmsg *ind[20];
    
        for (qint8 i = 0; i < 20; i++) {
            ind[i] = new getmsg (this,1333,768,i);
            ind[i]->updatePos(0,i*20);  // Next element 20 below
        }
    

    That works (in theory), the screen is filled with the objects, but when I try to click in a single element, to select it and edit, I can not.
    I can not select a single QLineEdit with the mouse. (Can I select only the QLineEdit elements from the last object)
    No Idea why that happens.

    Please can somebody help me to fix the issue?

    Thanks in advance.
    Greetings

    pd: The getmsg.cpp code

    //getmsg.cpp
    #include "getmsg.h"
    
    getmsg::getmsg(QWidget *parent, int _maxX, int _maxY, qint8 _nMsg)
        : QWidget(parent),maxX(_maxX),maxY(_maxY),nMsg(_nMsg)
    {
        resize(maxX,maxY);
        number = new QLabel(this);
      
        number->setText(QString::number(nMsg));
    
        getChannel = new QLineEdit(this);
        getChannel->resize(wgC,hLine);
    
        getMode = new QLineEdit(this);
        getMode->resize(wgM,hLine);
    
        get_tT = new QLineEdit(this);
        get_tT->resize(wgtT,hLine);
    
    }
    //******************************************************
    void getmsg::updatePos(int px, int py){
    
        px = origX+px;
        py = origY+py;
    
        number->move(px,py);
        px = px + wNumber +gSpace;
        circle->updatePos(px,py);
        px = px + radCircle + 2*gSpace;
        getChannel->move(px,py);
        px = px+wgC+gSpace; //last x origin
        getMode->move(px,py);
        px = px + wgM + gSpace;
        get_tT->move(px,py);
    }
    
    

  • Moderators

    @yczo Hallo! My first guess would be that your line edits are created before you call setupUi() and thus the central widget covers the line edits and gets all the clicks.



  • @Wieland Hello Wieland, really the complete code is:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        this->setFixedSize(1333,768);
    
       getmsg *ind[20];
        for (qint8 i = 0; i < 20; i++) {
            ind[i] = new getmsg (this,1333,768,i);
            ind[i]->updatePos(0,i*20);  // Next element 20 below
        }
    

    I did an error in the first post, I`m sorry :-(
    (thank you for answer)



  • Please,
    Any help would be appreciated. Also if the way to create the matrix is wrong, suggestions accepted
    Greetings


  • Lifetime Qt Champion

    Hi,

    Why not use a QVBoxLayout to contain your widgets ?



  • Thank you, I will take a look... But, with QVBoxLayout, can I too an Object make and multiply on the screen?

    Thank you very much, Greetings


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.