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. Problem with tableWidget component when QGraphicsOpacityEffect gradient reverts to opacity
Forum Updated to NodeBB v4.3 + New Features

Problem with tableWidget component when QGraphicsOpacityEffect gradient reverts to opacity

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 173 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.
  • 2hours2 Offline
    2hours2 Offline
    2hours
    wrote on last edited by
    #1

    When I use QGraphicsOpacityEffect to implement a gradient toggle for stackedWidgets, the tablewidget component on page 0 of the stackedWidget is not being restored to opacity properly, as indicated by the fact that its center background is restored to opacity but the column headers and sliders are transparent.

    The code is as follows:

    void MainWindow::on_pushButton_clicked()
    {
        QGraphicsOpacityEffect *effectOut = new QGraphicsOpacityEffect();
        QWidget *currentWidget = ui->stackedWidget->currentWidget();
        currentWidget->setGraphicsEffect(effectOut);
        QPropertyAnimation *animationOut = new QPropertyAnimation(effectOut, "opacity");
        animationOut->setDuration(100);
        animationOut->setStartValue(1.0);
        animationOut->setEndValue(0.0);
    
        QGraphicsOpacityEffect *effectIn = new QGraphicsOpacityEffect();
        QWidget *nextWidget = ui->stackedWidget->widget(0);
        nextWidget->setGraphicsEffect(effectIn);
        QPropertyAnimation *animationIn = new QPropertyAnimation(effectIn, "opacity");
        animationIn->setDuration(100);
        animationIn->setStartValue(0.0);
        animationIn->setEndValue(1.0);
    
        connect(animationOut, &QPropertyAnimation::finished, this, [this, nextWidget]() {
            ui->stackedWidget->setCurrentIndex(ui->stackedWidget->indexOf(nextWidget));
            ui->tableWidget->setGraphicsEffect(nullptr);
            ui->tableWidget->repaint();
            QCoreApplication::processEvents();
        });
    
        animationOut->start(QAbstractAnimation::DeleteWhenStopped);
        animationIn->start(QAbstractAnimation::DeleteWhenStopped);
    }
    

    I even tried to rewrite the tablewidget, but it still didn't work. The strange thing is that when I click on another program or click a bit on the tablewidget, it immediately reverts to opacity.

    I tried using update and repain, but that doesn't work either. I hope you can help me with this issue, thanks a lot!

    Pl45m4P 1 Reply Last reply
    0
    • 2hours2 2hours

      When I use QGraphicsOpacityEffect to implement a gradient toggle for stackedWidgets, the tablewidget component on page 0 of the stackedWidget is not being restored to opacity properly, as indicated by the fact that its center background is restored to opacity but the column headers and sliders are transparent.

      The code is as follows:

      void MainWindow::on_pushButton_clicked()
      {
          QGraphicsOpacityEffect *effectOut = new QGraphicsOpacityEffect();
          QWidget *currentWidget = ui->stackedWidget->currentWidget();
          currentWidget->setGraphicsEffect(effectOut);
          QPropertyAnimation *animationOut = new QPropertyAnimation(effectOut, "opacity");
          animationOut->setDuration(100);
          animationOut->setStartValue(1.0);
          animationOut->setEndValue(0.0);
      
          QGraphicsOpacityEffect *effectIn = new QGraphicsOpacityEffect();
          QWidget *nextWidget = ui->stackedWidget->widget(0);
          nextWidget->setGraphicsEffect(effectIn);
          QPropertyAnimation *animationIn = new QPropertyAnimation(effectIn, "opacity");
          animationIn->setDuration(100);
          animationIn->setStartValue(0.0);
          animationIn->setEndValue(1.0);
      
          connect(animationOut, &QPropertyAnimation::finished, this, [this, nextWidget]() {
              ui->stackedWidget->setCurrentIndex(ui->stackedWidget->indexOf(nextWidget));
              ui->tableWidget->setGraphicsEffect(nullptr);
              ui->tableWidget->repaint();
              QCoreApplication::processEvents();
          });
      
          animationOut->start(QAbstractAnimation::DeleteWhenStopped);
          animationIn->start(QAbstractAnimation::DeleteWhenStopped);
      }
      

      I even tried to rewrite the tablewidget, but it still didn't work. The strange thing is that when I click on another program or click a bit on the tablewidget, it immediately reverts to opacity.

      I tried using update and repain, but that doesn't work either. I hope you can help me with this issue, thanks a lot!

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

      @2hours said in Problem with tableWidget component when QGraphicsOpacityEffect gradient reverts to opacity:

      When I use QGraphicsOpacityEffect to implement a gradient toggle for stackedWidgets, the tablewidget component on page 0 of the stackedWidget is not being restored to opacity properly, as indicated by the fact that its center background is restored to opacity but the column headers and sliders are transparent.

      I'm not sure, can you show or explain further what you expect?

      I don't know what

      it immediately reverts to opacity

      means, but some things I've noticed:

      This line is meaningless

      ui->tableWidget->setGraphicsEffect(nullptr);

      since these lines

      QWidget *currentWidget = ui->stackedWidget->currentWidget();
      // ...
      QWidget *nextWidget = ui->stackedWidget->widget(0);
      

      return a plain "page" QWidget which holds your QTableWidget. So the QGraphicsOpacityEffect is applied to the page Widget, not the QTableView itself.
      (when you did everything in Designer)

      Also there might be something wrong with your logic... if you want to do what I think, then starting both animations at the same time and with same duration doesn't make any sense.
      Start the Fade-out, when finished, start the fade-in and flip the page of your QStackedWidget.

      It works for me, but some parts of the QTableWidget seem to ignore the opacity effect at all... they are never opaque or transparent. The background of the header and other widgets on the same page fade-in though.

      Edit:
      When setting the effect to the QTableWidget's viewport, the content fades in correctly (the header still doesn't)

      Seems like QTableWidget doesn't like being transparent :D
      Even though, setting the effect to the QStackedWidget' s page widget, should apply it to all children (as stated here)


      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
      0

      • Login

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