Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to hide the unnessary column of the qwidgetitem ?
Qt 6.12 LTS is out! See what's new in the release blog

How to hide the unnessary column of the qwidgetitem ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 2 Posters 1.9k 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.
  • nicker playerN nicker player

    When i used the qwidgetitem of the qt ui objects ,it comes out that an unnessary column on the last of the column.
    Esspesially when I scrolled to the maximum window,the last column of the qtablewidget became the longest column,so ugly.Idont know what to do or search information from the forum.
    Here's the code below.

    setSelectionBehavior(QAbstractItemView::SelectRows);  
        setSelectionMode(QAbstractItemView::SingleSelection); 
        setContextMenuPolicy(Qt::CustomContextMenu);// and how to add a menu trigger with this widgetitem?
        setAlternatingRowColors(true);
        verticalHeader()->setHidden(true); 
    
    //the code created the widgetitems of the qtablewidget
     for(int rowid = 0;rowid< rowCount;rowid++){
            UiBaseComponentTableWidgetItem * edititem = new UiBaseComponentTableWidgetItem();
            edititem->onCreateAllChild();
            int itemCount = colCount >= edititem->getContentCount() ? edititem->getContentCount() : colCount ;
           //***when the itemCount equals number 5,there would be 6 columns in the widget *** 
            for(int itemId = 0;itemId < itemCount;itemId++){
                QTableWidgetItem * tmpptr =(QTableWidgetItem *)edititem->getTableItem().at(itemId);
                setItem(rowid,itemId,tmpptr);
            }
            mTableItem.push_back(edititem);
        }
    
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

    it comes out that an unnessary column on the last of the column

    What does this mean please? Do you mean you get a column you don't need? Please explain better.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    nicker playerN 1 Reply Last reply
    0
    • jsulmJ jsulm

      @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

      it comes out that an unnessary column on the last of the column

      What does this mean please? Do you mean you get a column you don't need? Please explain better.

      nicker playerN Offline
      nicker playerN Offline
      nicker player
      wrote on last edited by
      #3

      @jsulm
      Yeah,
      Its hard to describe the container.
      For example,I just want 5 columns of the qtablewidget,but it appears 6 columns,and the last of the columns dosent have anything,It's just a blank column.I dont know howto hide it.

      jsulmJ 1 Reply Last reply
      0
      • nicker playerN nicker player

        @jsulm
        Yeah,
        Its hard to describe the container.
        For example,I just want 5 columns of the qtablewidget,but it appears 6 columns,and the last of the columns dosent have anything,It's just a blank column.I dont know howto hide it.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @nicker-player If you need 5 columns then insert 5 columns. If you get more then debug your code to see why you're inserting more columns (check itemCount in each iteration of the outer for loop).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        nicker playerN 1 Reply Last reply
        0
        • jsulmJ jsulm

          @nicker-player If you need 5 columns then insert 5 columns. If you get more then debug your code to see why you're inserting more columns (check itemCount in each iteration of the outer for loop).

          nicker playerN Offline
          nicker playerN Offline
          nicker player
          wrote on last edited by
          #5

          @jsulm
          In fact ,i dont think its the usage of the problem.I think its that maybe was the layout or something.
          When minimum the qtablewidget there would be the right columns,
          but once maximum the qtablewidget,there would be an extra column seemed in fact was not the column.Cause the last column has diffrent styles with the others before.
          I ve marked the area with the red pen.So god pleas help me .I dont know why.
          41261abb-8493-4f8e-a0d0-414b7f69e431-image.png

          jsulmJ 1 Reply Last reply
          0
          • nicker playerN nicker player

            @jsulm
            In fact ,i dont think its the usage of the problem.I think its that maybe was the layout or something.
            When minimum the qtablewidget there would be the right columns,
            but once maximum the qtablewidget,there would be an extra column seemed in fact was not the column.Cause the last column has diffrent styles with the others before.
            I ve marked the area with the red pen.So god pleas help me .I dont know why.
            41261abb-8493-4f8e-a0d0-414b7f69e431-image.png

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

            there would be an extra column

            It's not an extra column, it's simply empty space.
            Take a look at https://stackoverflow.com/questions/17411634/resizing-qtablewidget-columns-and-rows-to-fill-table

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            nicker playerN 2 Replies Last reply
            2
            • jsulmJ jsulm

              @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

              there would be an extra column

              It's not an extra column, it's simply empty space.
              Take a look at https://stackoverflow.com/questions/17411634/resizing-qtablewidget-columns-and-rows-to-fill-table

              nicker playerN Offline
              nicker playerN Offline
              nicker player
              wrote on last edited by nicker player
              #7

              @jsulm
              Yeah ,thanks a lot.
              But it would be not what I want.
              all the columns have the same width what looks like.
              I just wondered if there is a mode that do not have the empty space and user could modified the column width.

              Now I use the code like this

              QHeaderView * header = horizontalHeader();
                  header->setSectionResizeMode(QHeaderView::Interactive);
                  header->setCascadingSectionResizes(true);
                  header->setMinimumSectionSize(60);
                  header->setStretchLastSection(true);
              

              I just want to acommplish a function that the user could modified the width of the headerview columns
              by themself .
              But in fact once one of the columns was modified,the others after the one modified would disappear from the view area if I resize the column the max width.
              How could i do to prevent the user maximum the column not to be the max width or maybe this is what i want:
              when the user modified the column width there wouldnt appear the horizontal scorllbar of the headerview and all of the columns would be in the view area.
              Its very hard to describe the actions.

              jsulmJ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

                there would be an extra column

                It's not an extra column, it's simply empty space.
                Take a look at https://stackoverflow.com/questions/17411634/resizing-qtablewidget-columns-and-rows-to-fill-table

                nicker playerN Offline
                nicker playerN Offline
                nicker player
                wrote on last edited by
                #8

                @jsulm
                Could u help me ? it is very hard for me to find an easy way to fix the problem.

                1 Reply Last reply
                0
                • nicker playerN nicker player

                  @jsulm
                  Yeah ,thanks a lot.
                  But it would be not what I want.
                  all the columns have the same width what looks like.
                  I just wondered if there is a mode that do not have the empty space and user could modified the column width.

                  Now I use the code like this

                  QHeaderView * header = horizontalHeader();
                      header->setSectionResizeMode(QHeaderView::Interactive);
                      header->setCascadingSectionResizes(true);
                      header->setMinimumSectionSize(60);
                      header->setStretchLastSection(true);
                  

                  I just want to acommplish a function that the user could modified the width of the headerview columns
                  by themself .
                  But in fact once one of the columns was modified,the others after the one modified would disappear from the view area if I resize the column the max width.
                  How could i do to prevent the user maximum the column not to be the max width or maybe this is what i want:
                  when the user modified the column width there wouldnt appear the horizontal scorllbar of the headerview and all of the columns would be in the view area.
                  Its very hard to describe the actions.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

                  that the user could modified the width of the headerview columns

                  That should work by default

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  nicker playerN 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

                    that the user could modified the width of the headerview columns

                    That should work by default

                    nicker playerN Offline
                    nicker playerN Offline
                    nicker player
                    wrote on last edited by
                    #10

                    @jsulm
                    In fact its not.Because when i resize one of the columns to the maximum width, then the headview horizonal scollbar appears for a short time .only if i double click the headerview ,then the scrollbar disappeared and the width becomes normally.
                    So how to prevent this happened.I bind the headerview signal sectionResized to the method to control the width but failed.

                    jsulmJ 1 Reply Last reply
                    0
                    • nicker playerN nicker player

                      @jsulm
                      In fact its not.Because when i resize one of the columns to the maximum width, then the headview horizonal scollbar appears for a short time .only if i double click the headerview ,then the scrollbar disappeared and the width becomes normally.
                      So how to prevent this happened.I bind the headerview signal sectionResized to the method to control the width but failed.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #11

                      @nicker-player said in How to hide the unnessary column of the qwidgetitem ?:

                      I bind the headerview signal sectionResized to the method to control the width but failed

                      Please provide more details and show the code. Why do you do that at all?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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
                      • Unsolved