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. QFrame and QMainWindow
Qt 6.11 is out! See what's new in the release blog

QFrame and QMainWindow

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 8.1k 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.
  • UndeadBlowU Offline
    UndeadBlowU Offline
    UndeadBlow
    wrote on last edited by
    #1

    Hello everyone! I'm trying to set up over my main window translucent darkened "glass" like lightbox or something like that.
    Ok, I reached this by this code:
    @QFrame *f = new QFrame;
    f->setFrameStyle(QFrame::Box | QFrame::Plain);
    f->setWindowOpacity(0.5);
    f->setGeometry(this->geometry());
    f->setWindowFlags(Qt::FramelessWindowHint);
    f->setLineWidth(200);
    f->show();@

    Result:
    !http://pastexen.com/i/sgqsyzhp.png(Result)!

    But now frame is like another window:
    !http://pastexen.com/i/P6Zpj19Q.png(Taskbar)!

    Ofcouse it will not resize and move with my main window. If I will set this-parent in constructor of QFrame it will be incorrect result:
    !http://pastexen.com/i/XthE9vvO.png(Incorrect result)!

    What I can do with this to reach my goal?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      ByteWight
      wrote on last edited by
      #2

      I believe this is your problem:
      @f->setWindowFlags(Qt::FramelessWindowHint);@
      That's what makes your frame a window. Maybe you want this instead?
      @f->setFrameShape(QFrame::NoFrame);@

      1 Reply Last reply
      0
      • UndeadBlowU Offline
        UndeadBlowU Offline
        UndeadBlow
        wrote on last edited by
        #3

        [quote author="ByteWight" date="1367185042"]I believe this is your problem:
        @f->setWindowFlags(Qt::FramelessWindowHint);@
        That's what makes your frame a window. Maybe you want this instead?
        @f->setFrameShape(QFrame::NoFrame);@
        [/quote]
        Yea, thank you very much, main problem was in that

        1 Reply Last reply
        0
        • UndeadBlowU Offline
          UndeadBlowU Offline
          UndeadBlow
          wrote on last edited by
          #4

          Hmm. Now new problem. I want to put in the center of frame widget, but if it's widget parent will be not frame - it will be inactive under it. If set frame as parent - it will be transparent like frame, but I need to set it opaque:
          @
          this->setFrameStyle(QFrame::Box | QFrame::Plain);
          this->setWindowOpacity(0.6);
          this->setFrameShape(QFrame::Box);
          @
          !http://pastexen.com/i/HDFLYd08.png(Transparent)!
          What can I do, guys?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            ByteWight
            wrote on last edited by
            #5

            @this->setWindowOpacity(0.6);@

            You keep using these window functions when you shouldn't. They should only be used on window or dialog boxes. How about you try a stylesheet instead?

            @this->setStyleSheet("QFrame { background: rgba(255, 255, 255, 128); }");@

            (I did not test this out, but it should theoretically work)

            1 Reply Last reply
            0
            • UndeadBlowU Offline
              UndeadBlowU Offline
              UndeadBlow
              wrote on last edited by
              #6

              [quote author="ByteWight" date="1367273842"]@this->setWindowOpacity(0.6);@

              You keep using these window functions when you shouldn't. They should only be used on window or dialog boxes. How about you try a stylesheet instead?

              @this->setStyleSheet("QFrame { background: rgba(255, 255, 255, 128); }");@

              (I did not test this out, but it should theoretically work)[/quote]
              Now it is (=( have no idea why ):
              !http://s019.radikal.ru/i640/1304/aa/da60122e334e.png(Now)!

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rondog
                wrote on last edited by
                #7

                Instead of a window over top of the main window why not subclass paintEvent. Maybe something like this:

                @
                void MyWindow::paintEvent(QPaintEvent *event)
                {
                QPainter painter(this);

                 QMainWindow::paintEvent(event); // allow parent class to draw window
                
                 painter.fillRect(event->rect(),QColor(255,255,255,128)); //translucent color
                

                }
                @

                Edit: Never mind. This won't do what you want.

                1 Reply Last reply
                0
                • UndeadBlowU Offline
                  UndeadBlowU Offline
                  UndeadBlow
                  wrote on last edited by
                  #8

                  Any other ideas? :(((

                  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