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. Work with table
Forum Updated to NodeBB v4.3 + New Features

Work with table

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 727 Views 3 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.
  • V Offline
    V Offline
    Vlad02
    wrote on last edited by
    #1

    Hi everybody! So, I have next table:
    cda1c66e-bb6d-4d5e-a767-d3bba4aaf52a-image.png
    Unfortunallety, I don't have experience of using QTableWidget, but I need work with him. So, I have some problems:

    1. I set style of 'QTableWidget' with setStyleSheet, and items style set in the same way. But when I try edit cells, style of cells in editing change on style of mainwindow. I try create custom Delegate, but not good understand, how can change style in it. Besides I need check value in cells, when user input data. All data in cells - it's a hexadecimal numbers. I want to check, that user input value < FF and > 0. Otherwise, issue a warning and offer to enter the number again.
    2. How can I call editor not double-click mouse but by clicking on pushButton or pressing a button on the keyboard? And the same way close the editor and save data.

    I'm sorry for so big question, but I try understand this for two weeks and while unsuccess. I hope you will be able to help me. Thanks!

    Pl45m4P 1 Reply Last reply
    0
    • V Vlad02

      Hi everybody! So, I have next table:
      cda1c66e-bb6d-4d5e-a767-d3bba4aaf52a-image.png
      Unfortunallety, I don't have experience of using QTableWidget, but I need work with him. So, I have some problems:

      1. I set style of 'QTableWidget' with setStyleSheet, and items style set in the same way. But when I try edit cells, style of cells in editing change on style of mainwindow. I try create custom Delegate, but not good understand, how can change style in it. Besides I need check value in cells, when user input data. All data in cells - it's a hexadecimal numbers. I want to check, that user input value < FF and > 0. Otherwise, issue a warning and offer to enter the number again.
      2. How can I call editor not double-click mouse but by clicking on pushButton or pressing a button on the keyboard? And the same way close the editor and save data.

      I'm sorry for so big question, but I try understand this for two weeks and while unsuccess. I hope you will be able to help me. Thanks!

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Vlad02 said in Work with table:

      I set style of 'QTableWidget' with setStyleSheet, and items style set in the same way. But when I try edit cells, style of cells in editing change on style of mainwindow.

      What does your stylesheet look like? There are different options and styles for selected/edited rows/cols.

      • https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qtableview

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      V 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @Vlad02 said in Work with table:

        I set style of 'QTableWidget' with setStyleSheet, and items style set in the same way. But when I try edit cells, style of cells in editing change on style of mainwindow.

        What does your stylesheet look like? There are different options and styles for selected/edited rows/cols.

        • https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qtableview
        V Offline
        V Offline
        Vlad02
        wrote on last edited by
        #3

        @Pl45m4 My StyleSheet:

        QString StyleHelper::getMemoryStyle()
        {
            return "QTableWidget{"
                   "    border-left: 2px solid #555555;"
                   "    border-top: 2px solid #555555;"
                   "    border-right: 2px solid white;"
                   "    border-bottom: 2px solid white;"
                   "    background-color: black;"
                   "}"
                   "QTableWidget::item{"
                   "    background-color: black;"
                   "    border: 2px solid #555555;"
                   "    font-family: Undertale Battle Font;"
                   "    font-size: 14px;"
                   "}"
                   "QTableWidget::item:selected{"
                   "    background-color: red;"
                   "}";
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          For the delegate, the best is to not allow for invalid values to be entered in the first place. Use an hexadecimal spinbox.

          You have an example implementation in this stack overflow thread.

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

          V 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            For the delegate, the best is to not allow for invalid values to be entered in the first place. Use an hexadecimal spinbox.

            You have an example implementation in this stack overflow thread.

            V Offline
            V Offline
            Vlad02
            wrote on last edited by
            #5

            @SGaist Is it possible to not use a delegate? Or without it?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What is the issue in using a delegate to provide a custom editor ?

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

              V 1 Reply Last reply
              0
              • SGaistS SGaist

                What is the issue in using a delegate to provide a custom editor ?

                V Offline
                V Offline
                Vlad02
                wrote on last edited by
                #7

                @SGaist Rather, I don't really like the option with a spinbox. Will I be able to load data from a text file into such cells?

                M SGaistS 2 Replies Last reply
                0
                • V Vlad02

                  @SGaist Rather, I don't really like the option with a spinbox. Will I be able to load data from a text file into such cells?

                  M Offline
                  M Offline
                  mpergand
                  wrote on last edited by mpergand
                  #8

                  @Vlad02
                  What about a QLineEdit with an input mask/validator:
                  https://stackoverflow.com/questions/47517925/validate-text-in-qtablewidget

                  V 2 Replies Last reply
                  0
                  • M mpergand

                    @Vlad02
                    What about a QLineEdit with an input mask/validator:
                    https://stackoverflow.com/questions/47517925/validate-text-in-qtablewidget

                    V Offline
                    V Offline
                    Vlad02
                    wrote on last edited by
                    #9

                    @mpergand
                    Hm, this looks interesting. I will study this question, look for ways to do it in c++. Thank you!

                    1 Reply Last reply
                    0
                    • V Vlad02

                      @SGaist Rather, I don't really like the option with a spinbox. Will I be able to load data from a text file into such cells?

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Vlad02 said in Work with table:

                      @SGaist Rather, I don't really like the option with a spinbox. Will I be able to load data from a text file into such cells?

                      This is just an editor, it has nothing to do with how you load the data from your text file into the model.
                      You can write values as well into a spin box so from that point of view, it's a specialised QLineEdit that handles numerical values and in this case, A to F as well with the added benefit that users can use the controls or their arrow keys to increment/decrement the value.

                      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
                      • M mpergand

                        @Vlad02
                        What about a QLineEdit with an input mask/validator:
                        https://stackoverflow.com/questions/47517925/validate-text-in-qtablewidget

                        V Offline
                        V Offline
                        Vlad02
                        wrote on last edited by
                        #11

                        @mpergand
                        Thank you again, using a mask allowed me to get rid of the need to validate user input

                        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