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. QRadioButton elements inside a QlistWidget
QtWS25 Last Chance

QRadioButton elements inside a QlistWidget

Scheduled Pinned Locked Moved General and Desktop
qradiobuttonqlistwidget
6 Posts 2 Posters 4.6k 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.
  • C Offline
    C Offline
    CodeVisio
    wrote on last edited by
    #1

    Hello everyone,

    I'm a new QT developer.
    What I'd like to have as end result is a QListWidget where the list's items are QRadioButtons.
    Is that possible? And if it is, how could I implement that? Are there any examples to look from?

    Thank you

    p3c0P 1 Reply Last reply
    0
    • C CodeVisio

      Hello everyone,

      I'm a new QT developer.
      What I'd like to have as end result is a QListWidget where the list's items are QRadioButtons.
      Is that possible? And if it is, how could I implement that? Are there any examples to look from?

      Thank you

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      Hi @CodeVisio,
      Yes it is possible

      • Create new QListWidgetItem
      • Create new QRadioButton
      • Use setItemWidget to add that RadioButton as a List item in QListWidget
        For eg:
      QListWidget *list = new QListWidget();
      QListWidgetItem *listitem = new QListWidgetItem();
      list->setItemWidget(listitem,new QRadioButton("Radio Button"));
      

      157

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CodeVisio
        wrote on last edited by
        #3

        Hi p3c0,

        thank you for the answer.

        How about the click notifications? How can I be notified about the user click?

        Thanks

        p3c0P 1 Reply Last reply
        0
        • C CodeVisio

          Hi p3c0,

          thank you for the answer.

          How about the click notifications? How can I be notified about the user click?

          Thanks

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by p3c0
          #4

          @CodeVisio
          Use itemClicked(QListWidgetItem*) signal
          and then for that item use itemWidget() method to access widget inside it.

          157

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CodeVisio
            wrote on last edited by
            #5

            Thanks a lot @p3c0.

            One more thing.
            I can use QListWidget with check boxes (shown like QCheckBox) as elements inside it without
            this approach list->setItemWidget( listitem, new QCheckBox() ) , while for QRadioBoxes I have to explicitly create those object before inserting them inside the list.
            Is that a design choice? or is there a way to show QRadioBoxes inside the list as I can do with QCheckBoxes without creating them?

            Thanks again

            p3c0P 1 Reply Last reply
            0
            • C CodeVisio

              Thanks a lot @p3c0.

              One more thing.
              I can use QListWidget with check boxes (shown like QCheckBox) as elements inside it without
              this approach list->setItemWidget( listitem, new QCheckBox() ) , while for QRadioBoxes I have to explicitly create those object before inserting them inside the list.
              Is that a design choice? or is there a way to show QRadioBoxes inside the list as I can do with QCheckBoxes without creating them?

              Thanks again

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by p3c0
              #6

              @CodeVisio
              For checkboxes I think you must have set Qt::ItemIsUserCheckable flag for QListWidgetItem. So there's a way to do so. But for radiobutton theres none and thus have to create the widget explicitly.

              Edit: Links

              157

              1 Reply Last reply
              0

              • Login

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