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 make a tablewidget like this?
Forum Updated to NodeBB v4.3 + New Features

how to make a tablewidget like this?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 193 Views 1 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote last edited by
    #1

    0e068e52-c8b6-4c02-a6e2-368cf575ae4b-image.png
    I just want to make an object like this. when i hovered the item which looks like the up one.what should I do ?
    using the delegate of the qtablewidgetitem or putting so many parts of the qpushbutton into a widget ?

    Pl45m4P 1 Reply Last reply
    0
    • nicker playerN nicker player

      0e068e52-c8b6-4c02-a6e2-368cf575ae4b-image.png
      I just want to make an object like this. when i hovered the item which looks like the up one.what should I do ?
      using the delegate of the qtablewidgetitem or putting so many parts of the qpushbutton into a widget ?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by
      #2

      @nicker-player said in how to make a tablewidget like this?:

      using the delegate

      Yes.

      And since it's kinda custom view, I'd go for QTableView instead because it provides more flexibility


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

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • nicker playerN Offline
        nicker playerN Offline
        nicker player
        wrote last edited by
        #3

        so would u just post a little example for me ?
        I wrote a lot but failed.such as when hovered on the whole line of the row,the row comes out a white rectangle with the radius corner.
        I just thought if its more easier and effective by using the qwidgets instead of using the delegate.would u give me a little more advices?

        Pl45m4P 1 Reply Last reply
        0
        • nicker playerN nicker player

          so would u just post a little example for me ?
          I wrote a lot but failed.such as when hovered on the whole line of the row,the row comes out a white rectangle with the radius corner.
          I just thought if its more easier and effective by using the qwidgets instead of using the delegate.would u give me a little more advices?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote last edited by
          #4

          @nicker-player said in how to make a tablewidget like this?:

          so would u just post a little example for me ?

          "litte example" a.k.a I do it for you? No.

          I wrote a lot but failed

          Try harder. Post what you've done so far. It's definitely doable.


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

          ~E. W. Dijkstra

          nicker playerN 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @nicker-player said in how to make a tablewidget like this?:

            so would u just post a little example for me ?

            "litte example" a.k.a I do it for you? No.

            I wrote a lot but failed

            Try harder. Post what you've done so far. It's definitely doable.

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

            @Pl45m4 said in how to make a tablewidget like this?:

            doable

            void HoveredRowItemExtendDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
                //paintWordWrap(painter,option,index);
                if(option.state.testFlag(QStyle::State_Selected) || option.state.testFlag(QStyle::State_MouseOver)){
                    qDebug()<<"void HoveredRowItemExtendDelegate::paint()-QStyle::State_Selected";
                    //QTableWidgetItem *hoveredItem = tableWidget->item(index.row(), index.column());
                    //if(hoveredItem)
                    //{
                    const int row = index.row();
                    for(int column = 0; column < tableWidget->columnCount(); column++){
                        QTableWidgetItem *item = tableWidget->item(row, column);
                        if(item)
                        {
                            QModelIndex index = tableWidget->model()->index(row, column);
                            QStyleOptionViewItem itemOption = option;
                            itemOption.index = index;
                            itemOption.rect = tableWidget->visualItemRect(item);
                            QStyledItemDelegate::paint(painter, itemOption, index);
                        }
                    }
            
                    QTableWidgetItem *item0 = tableWidget->item(row, 0);
                    if(item0){
                        QRect rect = tableWidget->visualItemRect(item0);
                        bool value = index.data(Qt::CheckStateRole).toBool();
                        QStyleOptionButton checkBoxOption;
                        QRect checkBoxRect = QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkBoxOption);
                        checkBoxOption.rect = rect;// option.rect;
                        checkBoxOption.rect.setLeft(rect.left() + (rect.width() - checkBoxRect.width()) / 2);
                        checkBoxOption.rect.setTop(rect.top() + (rect.height() - checkBoxRect.height()) / 2);
                        checkBoxOption.state = value ? QStyle::State_On :QStyle::State_Off;
                        checkBoxOption.state |= QStyle::State_Enabled;
                        //auto pStyle = option.widget ? option.widget->style() : QApplication::style();
                        QCheckBox checkBox;
                        //checkBox.setStyleSheet(m_strStyleSheet);
                        checkBox.style()->drawControl(QStyle::CE_CheckBox, &checkBoxOption, painter, &checkBox);
                        //pStyle->drawPrimitive(QStyle::PE_IndicatorCheckBox, &checkBoxOption, painter,&checkBox);
                    }
                }
                //}
                else{
                    //m_CheckBox->hide();
                    return QStyledItemDelegate::paint(painter, option, index);
                }
            
            }
            

            by the way .which one should i choose .the qlistview or qtableview.

            1 Reply Last reply
            0
            • GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote last edited by
              #6

              Doing this in QWidgets looks like a pain in the ass. It would be pretty easy to do in Qt Quick.

              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