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. QTableWidget issue with text overlap in editable text box
Forum Updated to NodeBB v4.3 + New Features

QTableWidget issue with text overlap in editable text box

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 3.0k Views 2 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.
  • N Offline
    N Offline
    notalocal
    wrote on 23 Sept 2016, 18:38 last edited by
    #1

    I am currently having an issue in Qt 5.7 where a text edit box in my QTableWidget leaves old text in the box as new text is being entered. So for example if I am typing into a box where the previous value was "9999", I will see my new values entered on top of the old "9999" value.

    From what little I can find on people having similar issues, I think it has to do with using transparency in the QSS style sheet for my table widget, but I can't remove the transparency as it is needed for the UI design. My current style sheet is set as:

    this->setStyleSheet("QWidget{background-color: transparent; color: #ffffff;}"
    "QTableWidget{alternate-background-color: #70505050;background-color:transparent;gridline-color: #7f7f7f;}"
    "QTableWidget::item{selection-color: #ffffff; selection-background-color: #0010cf;}"
    "QLineEdit#nameEdit{color: black; background-color: white;}"
    "QHeaderView::section{ background-color: #7f003464; padding: 4px; border-style: none; border-bottom: 1px solid #7fffffff; border-right: 1px solid #7fffffff;border-left: 1px solid #7fffffff;}"
    "QHeaderView::section:horizontal{border-top: 1px solid #7fffffff;}"
    "QHeaderView::section:vertical{border-left: 1px solid #7fffffff;}");

    I have been banging my head on a wall for a couple hours now, so if anyone has any pointers on how I can fix this issue or help me find a workaround that would be greatly appreciated.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      notalocal
      wrote on 26 Sept 2016, 18:08 last edited by
      #9

      Thanks for the help everyone! I was able to fix my issue by removing the QWidget portion of my style sheet. Now when I edit text it shows a white text edit box instead of giving the overlap. Here is my working style sheet solution.

      this->setStyleSheet("QTableWidget{alternate-background-color: #70505050; color: white; background-color:transparent;gridline-color: #7f7f7f;}"
                                  "QTableWidget::item{selection-color: #ffffff; selection-background-color: #0010cf;}"
                                  "QHeaderView::section{ background-color: #99A3A4; padding: 4px; border-style: none; border-bottom: 1px solid #7fffffff; border-right: 1px solid #7fffffff;border-left: 1px solid #7fffffff;}"
                                  "QHeaderView::section:horizontal{border-top: 1px solid #7fffffff;}"
                                  "QHeaderView::section:vertical{border-left: 1px solid #7fffffff;}");
      
      1 Reply Last reply
      2
      • N Offline
        N Offline
        notalocal
        wrote on 23 Sept 2016, 18:43 last edited by
        #2

        Also note that the QTableWidgetItem that I assign to the QTableWidget spaces where an editable text box is needed has no style sheet of its own.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Sept 2016, 20:53 last edited by
          #3

          Hi and welcome to devnet,

          Do you really need to have all your widgets to have a transparent background ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • N Offline
            N Offline
            notalocal
            wrote on 23 Sept 2016, 23:10 last edited by
            #4

            I mean if I had a choice I would probably make the UI not require a transparent table over a background image, but those aren't the specifications for this element (I don't really have any say in it). Do you ask because you see it as impossible to workaround this issue?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 23 Sept 2016, 23:23 last edited by
              #5

              Hi
              I do wonder if you tried to disable the stylesheets to check if issue comes from it.

              1 Reply Last reply
              1
              • N Offline
                N Offline
                notalocal
                wrote on 23 Sept 2016, 23:35 last edited by
                #6

                Disabling the style sheet does in fact remove my issue of overlap, but then creates the new issue of no longer having the transparent table. I know this seems like one of those "Doctor it hurts when I move my leg like this situations", but ideally I would like to figure out how to make both things work.

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 24 Sept 2016, 19:21 last edited by
                  #7

                  That because your style sheet first line is QWidget{background-color: transparent; color: #ffffff;} which means the transparency will be applied to all widgets that are children of your QTableWidget which the editors will be.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • N Offline
                    N Offline
                    notalocal
                    wrote on 26 Sept 2016, 15:17 last edited by
                    #8

                    That actually makes sense... I would think that the alternate color style sheet would at least override that one, but I guess the QWidget sheet takes precedence. I'm going to try moving the transparent coloring to the table color sheet to see if that fixes my issue.

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      notalocal
                      wrote on 26 Sept 2016, 18:08 last edited by
                      #9

                      Thanks for the help everyone! I was able to fix my issue by removing the QWidget portion of my style sheet. Now when I edit text it shows a white text edit box instead of giving the overlap. Here is my working style sheet solution.

                      this->setStyleSheet("QTableWidget{alternate-background-color: #70505050; color: white; background-color:transparent;gridline-color: #7f7f7f;}"
                                                  "QTableWidget::item{selection-color: #ffffff; selection-background-color: #0010cf;}"
                                                  "QHeaderView::section{ background-color: #99A3A4; padding: 4px; border-style: none; border-bottom: 1px solid #7fffffff; border-right: 1px solid #7fffffff;border-left: 1px solid #7fffffff;}"
                                                  "QHeaderView::section:horizontal{border-top: 1px solid #7fffffff;}"
                                                  "QHeaderView::section:vertical{border-left: 1px solid #7fffffff;}");
                      
                      1 Reply Last reply
                      2

                      1/9

                      23 Sept 2016, 18:38

                      • Login

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