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. Accessing combo and textbox values
Forum Updated to NodeBB v4.3 + New Features

Accessing combo and textbox values

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.6k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    DaveTheBrave
    wrote on 16 May 2013, 13:15 last edited by
    #1

    I'm using Python 3 and QT4 with pyqt. I'm using Designer. I've been unable to access data from qcomboboxes and qplaintextedits.

    I've read the documentation here: http://qt-project.org/doc/qt-4.8/qcombobox.html http://qt-project.org/doc/qt-4.8/qplaintextedit.html

    The only thing on these pages that appears to describe how to pull the selected value are 'plainText' for the plain text box and 'currentText' for the combo box. These aren't explicitly described as the solution, but they're the only thing I found that makes sense.

    They do not return errors, but both the combo boxes and text boxes return the default value I set in QT designer, regardless of what is currently selected when running the program. Any ideas?

    Example code I'm using:

    x = window.ui.tb_x.toPlainText()
    y = window.ui.cb_y.currentText()

    I've also tried
    y = window.ui.cb_y.itemData(window.ui.currentIndex())

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 16 May 2013, 13:35 last edited by
      #2

      what do you expect getting from the QPlainTextEdit other than its plain text it is holding?!

      For the comboBox try this:
      @
      QVariant v = window.ui.cb_y.itemData(window.ui.currentIndex(), Qt::DispalyRole);
      @

      But i'm just guessing since you haven't mentioned what you actually want to get out of these widgets?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jeroentjehome
        wrote on 16 May 2013, 13:44 last edited by
        #3

        Hi, When in designer a couple of items have been inserted in a QComboBox, the currentText() should return the QString present at that time. It does work for me, have you debugged the code? Maybe you make an error along the way ;-)
        Greetz

        Greetz, Jeroen

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DaveTheBrave
          wrote on 16 May 2013, 14:34 last edited by
          #4

          Thank you for the help. It turns out that my code was structured incorrectly for QT. I have a separate class in my program for each QT window. Functions that take input seem to only work when in this class, not in my main program body. I moved the input function to it's window's class, and changed the widget prefixes to 'self.ui'. Problem solved.

          Raven: I was expecting the current value, not the default one. Ie, I set in Designer that a text box shows 'apples' initially. I run the program, change the box to 'oranges'. The program thinks the input is 'apples'.

          1 Reply Last reply
          0

          1/4

          16 May 2013, 13:15

          • Login

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