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. Own popup window
Forum Updated to NodeBB v4.3 + New Features

Own popup window

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 381 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.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1

    Instead of comboBox, I want pull down window on button click.
    In general, this window should have any content: for example multi-column, colored, etc.
    For simple case - this will list of strings.
    This window should be modal and automatic close if click for any point of application.
    Will be best (but not necessary) not closing window if we open it, go to other application and back.
    How do it?

    JonBJ 1 Reply Last reply
    0
    • A Offline
      A Offline
      AndrzejB
      wrote on last edited by
      #4

      Sample solution code on gist:
      gist Popup.cpp and .h

      1 Reply Last reply
      0
      • A AndrzejB

        Instead of comboBox, I want pull down window on button click.
        In general, this window should have any content: for example multi-column, colored, etc.
        For simple case - this will list of strings.
        This window should be modal and automatic close if click for any point of application.
        Will be best (but not necessary) not closing window if we open it, go to other application and back.
        How do it?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @AndrzejB
        Probably with a Qt popup window/widget, with whatever inside it.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AndrzejB
          wrote on last edited by AndrzejB
          #3

          I do

          void SearchBar::adjustPopup() {
              if (!popup->isVisible()) {
                  return;
              }
              QRect rect = button->geometry();
              QPoint bottomLeft = this->mapToGlobal(rect.bottomLeft());
              popup->setGeometry(QRect(bottomLeft, QSize(rect.width(),200)));
          }
          
          void SearchBar::resizeEvent(QResizeEvent *event)
          {
              QWidget::resizeEvent(event);
              adjustPopup();
          }
          
          void SearchBar::moveEvent(QMoveEvent *event)
          {
              QWidget::moveEvent(event);
              adjustPopup();
          }
          ...............
          popup = new QWidget(editor);
              popup->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
              connect(button,&QPushButton::clicked,[=](){
                  popup->setVisible(!popup->isVisible());
                  adjustPopup();
              });
          

          is problem: moveEvent is called on resize, but in my Mint Cinnamon, no moveEvent is produced during drag window.
          try solution:
          No moveEvent of my widget, but I must see moveEvent of Application

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AndrzejB
            wrote on last edited by
            #4

            Sample solution code on gist:
            gist Popup.cpp and .h

            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