Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QInputDialog with a checkbox
QtWS25 Last Chance

Using QInputDialog with a checkbox

Scheduled Pinned Locked Moved General and Desktop
qinputdialogc++gui
3 Posts 3 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Onikouzou
    wrote on last edited by
    #1

    Are you able to use a checkbox inside an QInputDialog window? I want to prompt the user to be able to choose from about 25 different options that will be used as mutators elsewhere in the program.

    This is what I have right now. It doesn't compile at all, but basically I'm trying to use the combobox inside the QInputDIalog box.

    QCheckBox sounds;
    QInputDialog showSounds;
    QStringList soundList;
    soundList << sounds.setText("Sound 1");
    
    showSounds.setOptions(QInputDialog::UseListViewForComboBoxItems);
    showSounds.setComboBoxItems(soundList);
    showSounds.setWindowTitle("Select sounds");
    showSounds.exec();
    

    Thanks for the answer ahead of time.

    jsulmJ 1 Reply Last reply
    0
    • joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

      Hi friend. welcome!
      void setText(const QString &text) return void. and you used soundList << sounds.setText("Sound 1"); I didn't understand it. It is wrong.

      And I saw the qt help about the QInputDialog

      The QInputDialog class provides a simple convenience dialog to get a single value from the user.
      The input value can be a string, a number or an item from a list ...

      About the an item from list

      void setComboBoxItems(const QStringList &items); ///< It is the ComboBox item. Not the CheckBox.

      so, if you want to have the checkbox.

      1. First solution: You can subclass QDialog. i think it is easy and good solution.
      2. Second solution: I saw the QComboBox, and you can try using void setItemDelegate(QAbstractItemDelegate *delegate)
        to delegate the checkbox. It is complex i think.

      maybe someone has the better answer. best wish for you.

      Just do it!

      1 Reply Last reply
      0
      • O Onikouzou

        Are you able to use a checkbox inside an QInputDialog window? I want to prompt the user to be able to choose from about 25 different options that will be used as mutators elsewhere in the program.

        This is what I have right now. It doesn't compile at all, but basically I'm trying to use the combobox inside the QInputDIalog box.

        QCheckBox sounds;
        QInputDialog showSounds;
        QStringList soundList;
        soundList << sounds.setText("Sound 1");
        
        showSounds.setOptions(QInputDialog::UseListViewForComboBoxItems);
        showSounds.setComboBoxItems(soundList);
        showSounds.setWindowTitle("Select sounds");
        showSounds.exec();
        

        Thanks for the answer ahead of time.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Onikouzou What is this checkbox used for?
        If you only want to use a combobox then do:

        QInputDialog showSounds;
        QStringList soundList;
        soundList << "Sound 1" << "Sound 2";
        showSounds.setOptions(QInputDialog::UseListViewForComboBoxItems); // Remove this if you want a combobox instead of a list
        showSounds.setComboBoxItems(soundList);
        showSounds.setWindowTitle("Select sounds");
        showSounds.exec();
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved