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. How to draw a continuous vertical line on QTableView?
QtWS25 Last Chance

How to draw a continuous vertical line on QTableView?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.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.
  • M Offline
    M Offline
    mehmety888
    wrote on last edited by mehmety888
    #1

    Hi,

    • Qt Version: 5.9.7
    • Must be using QTableView to create tables.
    • There must be gridlines (horizontal and vertical) for Table items.
    • We add pushbuttons using setIndexWidget to some cells.
    • We want to create a vertical line with blue color on right side of these cells. (with pushbuttons)

    We used following code block to create blue border at the right of the cells:

    QPushButton *push_button = new QPushButton();
    push_button ->setStyleSheet("border-right: 3px solid blue;"
                                "padding-right: 4px;"
                                "background-color:none;");
    setIndexWidget(in_p_model->index(row_idx,column_idx), push_button );
    

    The resulting table is shown below.
    vline.png

    What is not acceptable for us is table gridlines(gray) overlap on our blue lines that we have created.

    We want vertical like below (We drew at paint :D )
    vlinesolved.jpg

    Please let us know how can we prevent gridlines to overlap our vertical lines (blue) ?
    Many Thanks,

    1 Reply Last reply
    2
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, I had almost same problem, for a QTableWidget, and I wanted an horizontal line unobscured by the gridlies.

      I ended up created an horizontal QFrame:

      ...
      auto qf = new QFrame(ui->tableWidget->viewport());
      qf->setFrameShape(QFrame::HLine);
      qf->setFrameShadow(QFrame::Plain);
      qf->show();
      ....
      

      (and I calculated the width etc. from ui->listWidget->viewport()->width() and ui->listWidget0->rowAt(0) ..)

      M 2 Replies Last reply
      3
      • hskoglundH hskoglund

        Hi, I had almost same problem, for a QTableWidget, and I wanted an horizontal line unobscured by the gridlies.

        I ended up created an horizontal QFrame:

        ...
        auto qf = new QFrame(ui->tableWidget->viewport());
        qf->setFrameShape(QFrame::HLine);
        qf->setFrameShadow(QFrame::Plain);
        qf->show();
        ....
        

        (and I calculated the width etc. from ui->listWidget->viewport()->width() and ui->listWidget0->rowAt(0) ..)

        M Offline
        M Offline
        mehmety888
        wrote on last edited by
        #3

        @hskoglund

        We tried the codeblock you've shared but it does not show anything. Please could you share remaining parts of the code.

        QFrame* Frame = new QFrame(this->viewport());
        Frame ->setFrameShape(QFrame:VLine);
        Frame ->setFrameShadow(QFrame::Plain);
        Frame ->show();
        setIndexWidget(in_p_model->index(row_idx,column_idx), Frame);
        
        JonBJ 1 Reply Last reply
        0
        • M mehmety888

          @hskoglund

          We tried the codeblock you've shared but it does not show anything. Please could you share remaining parts of the code.

          QFrame* Frame = new QFrame(this->viewport());
          Frame ->setFrameShape(QFrame:VLine);
          Frame ->setFrameShadow(QFrame::Plain);
          Frame ->show();
          setIndexWidget(in_p_model->index(row_idx,column_idx), Frame);
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @mehmety888
          @hskoglund wrote to you:

          (and I calculated the width etc. from ui->listWidget->viewport()->width() and ui->listWidget0->rowAt(0) ..)

          How did you act on that?

          M 1 Reply Last reply
          1
          • JonBJ JonB

            @mehmety888
            @hskoglund wrote to you:

            (and I calculated the width etc. from ui->listWidget->viewport()->width() and ui->listWidget0->rowAt(0) ..)

            How did you act on that?

            M Offline
            M Offline
            mehmety888
            wrote on last edited by
            #5

            @JonB Ok I understand now why it is not shown. I needed to set the border width.

            p_frame->setFixedHeight(total_cell_height);
            p_frame->setStyleSheet( "border-width: 3px;"
                                    "border-top-style: none;"
                                    "border-right-style: solid;"
                                    "border-bottom-style: none;"
                                    "border-left-style: none;"
                                    "border-color: blue;");
            
            1 Reply Last reply
            0
            • hskoglundH hskoglund

              Hi, I had almost same problem, for a QTableWidget, and I wanted an horizontal line unobscured by the gridlies.

              I ended up created an horizontal QFrame:

              ...
              auto qf = new QFrame(ui->tableWidget->viewport());
              qf->setFrameShape(QFrame::HLine);
              qf->setFrameShadow(QFrame::Plain);
              qf->show();
              ....
              

              (and I calculated the width etc. from ui->listWidget->viewport()->width() and ui->listWidget0->rowAt(0) ..)

              M Offline
              M Offline
              mehmety888
              wrote on last edited by
              #6

              @hskoglund Many thanks for your help :)

              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