Results 1 to 5 of 5

Thread: Very new to QT-Creator struggling with combobox and push button

  1. #1
    Join Date
    Jun 2017
    Location
    Digital Nomad (Global - currently Asia)
    Posts
    3
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Very new to QT-Creator struggling with combobox and push button

    Hi guys im struggling with making a push button reset 6 different (but all horizontally aligned) widgets. the code im currently using is as follows:

    Qt Code:
    1. void MainWindow::on_button_clicked()
    2. {
    3. ui->lineEdit1->clear();
    4. ui->lineEdit2->clear();
    5. ui->combobox1->clear();
    6. ui->lineEdit3->clear();
    7. ui->lineEdit4->clear();
    8. ui->combobox2->clear();
    9. }
    To copy to clipboard, switch view to plain text mode 

    The line edits clear perfectly but the comboBoxes delete all the information I have previously keyed in. How would I instead have the pushButton reset the combobox back to the original starting selection.

    eg: --- is the standard then 1, 2, 3, so i would want to go back to --- but still be able to select 1, 2, 3


    Second question would be I have to do this for 20 lines, all the same as above only labeled 1 - 20 eg tMT1 - tMT20, bTN1 - bTN20. Is there a way to make the code DRY ????


    Added after 1 2 minutes:


    Figured it out correct code is

    ui->combobox1->setCurrentIndex(WhatEverTheOriginalWas);

    UPDATE

    DO NOT type the selection i.e mine is ---, 1, 2, 3, etc it is 0 for ---, 1 for 1, 2 for 2, and so on

    code would be

    ui->combo1->setCurrentIndex(0);

    (mine is 0 because i want --- to be displayed)
    Last edited by MrCrackPotBuilder; 28th June 2017 at 09:51.

  2. #2
    Join Date
    Jun 2017
    Location
    Digital Nomad (Global - currently Asia)
    Posts
    3
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Very new to QT-Creator struggling with combobox and push button

    I still need help to DRY the code as i now have whats above repeated 20 times just with the ending number changing if anyone knows how to it would be amazing

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,461
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Very new to QT-Creator struggling with combobox and push button

    Read about QObject::findChildren() especially the version with QRegExp.

  4. #4
    Join Date
    Jun 2017
    Location
    Digital Nomad (Global - currently Asia)
    Posts
    3
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Very new to QT-Creator struggling with combobox and push button

    Thanks a bunch once i figure it out i will again update the thread with process and code

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Very new to QT-Creator struggling with combobox and push button

    An alternative discussed in another thread is to use Qt Designer to create your UI, and then at startup after calling setupUi() you copy the pointers into QVector< QPushButton * >, etc. See this thread.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. push button twice different text
    By Kloster in forum Newbie
    Replies: 10
    Last Post: 2nd September 2016, 18:17
  2. Action using Push Button ?
    By steve.bush in forum Newbie
    Replies: 7
    Last Post: 25th February 2016, 15:36
  3. push button
    By arumita in forum Newbie
    Replies: 1
    Last Post: 3rd June 2014, 01:02
  4. Hareware Push Button
    By mickeyk191 in forum Newbie
    Replies: 2
    Last Post: 26th January 2010, 12:41
  5. Push Button problem!!
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2006, 16:31

Tags for this Thread

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.