Results 1 to 3 of 3

Thread: QWidget::setTabOrder question

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QWidget::setTabOrder question

    Hi!
    I wrote a dialog to input valid car plates (Portuguese format: http://pt.wikipedia.org/wiki/Matr%C3...is_em_Portugal )using Qt Designer. It works just fine.

    Then i tried to write it again, but now not using Qt Designer.
    This second version works but i get the following message :

    Qt Code:
    1. Starting /home/torrao/Desktop/v7/automovel_sem_designer/automovel_sem_designer
    2. QWidget::setTabOrder: 'first' and 'second' must be in the same window
    3. QWidget::setTabOrder: 'first' and 'second' must be in the same window
    4. /home/torrao/Desktop/v7/automovel_sem_designer/automovel_sem_designer exited with code 0
    To copy to clipboard, switch view to plain text mode 

    This must be an insignificant detail ... but i would apreciate some help

    The code:
    IdDoAutomovel.h
    Qt Code:
    1. #ifndef IDDOAUTOMOVELDIALOG_H
    2. #define IDDOAUTOMOVELDIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. class QLabel;
    7. class QLineEdit;
    8. class QString;
    9. class QRegExp;
    10.  
    11. class IdDoAutomovelDialog : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. IdDoAutomovelDialog(QWidget *parent = 0);
    17.  
    18. private slots:
    19. void on_lineEdit_textChanged();
    20.  
    21. private:
    22. QLabel *label;
    23. QLineEdit *lineEdit;
    24. QSpacerItem *horizontalSpacer;
    25. QPushButton *okButton;
    26. QPushButton *cancelButton;
    27. QStringList *listaMatriculasValidas;
    28. QVBoxLayout *verticalLayout;
    29. QHBoxLayout *horizontalLayout;
    30. QHBoxLayout *horizontalLayout_2;
    31. };
    32.  
    33. #endif // IDDOAUTOMOVELDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    IdDoAutomovel.cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "IdDoAutomovelDialog.h"
    4.  
    5. IdDoAutomovelDialog::IdDoAutomovelDialog(QWidget *parent):QDialog(parent){
    6. //Label
    7. label = new QLabel("&MatrÃ*cula:");
    8.  
    9. //Line Edit
    10. lineEdit = new QLineEdit;
    11.  
    12. //Buddyes
    13. label->setBuddy(lineEdit);
    14.  
    15. //Spacer
    16. horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    17.  
    18. //OK Button
    19. okButton = new QPushButton("Ok");
    20. okButton->setEnabled(false);
    21.  
    22. //CANCEL Button
    23. cancelButton = new QPushButton("Cancel");
    24. cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
    25.  
    26. //Validar a matrÃ*cula introduzida ( http://pt.wikipedia.org/wiki/Matr%C3%ADculas_autom%C3%B3veis_em_Portugal )
    27. listaMatriculasValidas = new QStringList;
    28. listaMatriculasValidas->append("[A-Za-z]{2,2}[-][0-9]{2,2}[-][0-9]{2,2}");
    29. listaMatriculasValidas->append("[0-9]{2,2}[-][0-9]{2,2}[-][A-Za-z]{2,2}"); //or
    30. listaMatriculasValidas->operator <<("[0-9]{2,2}[-][A-Za-z]{2,2}[-][0-9]{2,2}");
    31. QRegExp regExp(listaMatriculasValidas->join("|"));
    32. lineEdit->setValidator(new QRegExpValidator(regExp, this));
    33.  
    34. //Definir acções
    35. connect(lineEdit, SIGNAL(textChanged(const QString &)),
    36. this, SLOT(on_lineEdit_textChanged()));
    37.  
    38. connect(okButton, SIGNAL(clicked()),
    39. this, SLOT(accept()));
    40. connect(cancelButton, SIGNAL(clicked()),
    41. this, SLOT(close()));
    42.  
    43. //layout Dialog
    44. horizontalLayout = new QHBoxLayout;
    45. horizontalLayout_2 = new QHBoxLayout;
    46. verticalLayout = new QVBoxLayout;
    47.  
    48. horizontalLayout->addWidget(label);
    49. horizontalLayout->addWidget(lineEdit);
    50.  
    51. horizontalLayout_2->addItem(horizontalSpacer);
    52. horizontalLayout_2->addWidget(okButton);
    53. horizontalLayout_2->addWidget(cancelButton);
    54.  
    55. verticalLayout->addLayout(horizontalLayout);
    56. verticalLayout->addLayout(horizontalLayout_2);
    57.  
    58. //Tab order
    59. QWidget::setTabOrder(lineEdit, okButton);
    60. QWidget::setTabOrder(okButton, cancelButton);
    61.  
    62. setWindowTitle("MatrÃ*cula");
    63. setLayout(verticalLayout);
    64. }
    65.  
    66. void IdDoAutomovelDialog::on_lineEdit_textChanged(){
    67. okButton->setEnabled(lineEdit->hasAcceptableInput());
    68. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget::setTabOrder question

    Try moving the tab ordering code after the last setLayout() OR pass "this" as parent to "lineEdit", "okButton" and "cancelButton".
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    missoni (20th April 2011)

  4. #3
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWidget::setTabOrder question

    Try moving the tab ordering code after the last setLayout()
    Thanks, that was it

Similar Threads

  1. SQL Question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 19:36
  2. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 17:14
  3. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  4. Replies: 1
    Last Post: 15th March 2007, 20:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.