Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. how to selectall text inside an editable QComboBox (pyqt or pyside)
Forum Updated to NodeBB v4.3 + New Features

how to selectall text inside an editable QComboBox (pyqt or pyside)

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 1.0k 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.
  • adfinem_risingA Offline
    adfinem_risingA Offline
    adfinem_rising
    wrote on last edited by adfinem_rising
    #1

    I am trying to create a combobox that has font sizes in it. similar to microsoft word fontsize combobox.
    i just would like to know, how do you select all the text inside an editable combobox when the user clicks on it?

    this does not seem to work:
    self.font_size_combo_box.lineEdit().selectAll

    and also this:
    self.font_size_combo_box.lineEdit().setCursorPosition(0)

    thanks in advance. i really have no idea how to have the text in the comboBox be selected whenever user clicks in the comboBox.

    def prevent_null_entry(self):
            any_unique_value = 1
            validation_rule = QDoubleValidator(1,99,0)
           print(validation_rule.validate(self.font_size_combo_box.currentText(),any_unique_value))
    
            if validation_rule.validate(self.font_size_combo_box.currentText(), any_unique_value)[0] == QValidator.Acceptable:
                self.font_size_combo_box.lineEdit().setCursorPosition(0)
            else:
                # message box warning
                qtw.QMessageBox.warning(self,"Can't leave this input field blank","Please type-in your desired font size between [1 to 99]",qtw.QMessageBox.StandardButton.Ok)
                self.font_size_combo_box.lineEdit().selectAll
                self.font_size_combo_box.setCurrentText(str(13))
    
    JonBJ 1 Reply Last reply
    0
    • adfinem_risingA adfinem_rising

      I am trying to create a combobox that has font sizes in it. similar to microsoft word fontsize combobox.
      i just would like to know, how do you select all the text inside an editable combobox when the user clicks on it?

      this does not seem to work:
      self.font_size_combo_box.lineEdit().selectAll

      and also this:
      self.font_size_combo_box.lineEdit().setCursorPosition(0)

      thanks in advance. i really have no idea how to have the text in the comboBox be selected whenever user clicks in the comboBox.

      def prevent_null_entry(self):
              any_unique_value = 1
              validation_rule = QDoubleValidator(1,99,0)
             print(validation_rule.validate(self.font_size_combo_box.currentText(),any_unique_value))
      
              if validation_rule.validate(self.font_size_combo_box.currentText(), any_unique_value)[0] == QValidator.Acceptable:
                  self.font_size_combo_box.lineEdit().setCursorPosition(0)
              else:
                  # message box warning
                  qtw.QMessageBox.warning(self,"Can't leave this input field blank","Please type-in your desired font size between [1 to 99]",qtw.QMessageBox.StandardButton.Ok)
                  self.font_size_combo_box.lineEdit().selectAll
                  self.font_size_combo_box.setCurrentText(str(13))
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @adfinem_rising said in how to selectall text inside an editable QComboBox (pyqt or pyside):

      self.font_size_combo_box.lineEdit().selectAll

      I don't know about your whole question [actually this might be the answer], but since that's a function call you need to add the ()....

      adfinem_risingA 1 Reply Last reply
      1
      • JonBJ JonB

        @adfinem_rising said in how to selectall text inside an editable QComboBox (pyqt or pyside):

        self.font_size_combo_box.lineEdit().selectAll

        I don't know about your whole question [actually this might be the answer], but since that's a function call you need to add the ()....

        adfinem_risingA Offline
        adfinem_risingA Offline
        adfinem_rising
        wrote on last edited by
        #3

        @JonB OMG!!! hahaha that was the answer all along?! i was sitting here wondering why it was not working!! thanks!!

        JonBJ 1 Reply Last reply
        0
        • adfinem_risingA adfinem_rising

          @JonB OMG!!! hahaha that was the answer all along?! i was sitting here wondering why it was not working!! thanks!!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @adfinem_rising
          Does Python not warn you about accidentally using a function on a statement of its own without the ()s? Else it's going to be a pretty common gotcha....

          adfinem_risingA 1 Reply Last reply
          0
          • JonBJ JonB

            @adfinem_rising
            Does Python not warn you about accidentally using a function on a statement of its own without the ()s? Else it's going to be a pretty common gotcha....

            adfinem_risingA Offline
            adfinem_risingA Offline
            adfinem_rising
            wrote on last edited by
            #5

            @JonB not really, im using visual studio code and it does not say anything to me. it just doesn't give an error and the application does not crash. so i couldn't understand what was happening. thanks again for the answer, i spent the wholeday googling. who knows maybe i would have been googling for a month and still not get a solution lol

            i got that selectall code from stackoverflow and it didnt have the () at the end

            1 Reply Last reply
            1

            • Login

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