The main window freeze for a couple of seconds while opening/closing a dialog. What is a remedy?

  • Hey Bros,
    I have a main window with more than 200 elements that are updating every 500 milliseconds. The update includes changing the apparent (mostly the color) of every element by their Qpainter through an update function in main window.
    I have a widget window in main window that is invisible.
    when i click on these elements,that widget will be shown.
    but in the interval of showing/closing that widget, my main window freezes for some seconds.
    How can i solve this problem??
    Thanks a lot.

  • Lifetime Qt Champion


    What kind of information are you showing ?

  • on my main window i show numbers and small symbols (more than 200 elements) that their color or icon is changing by their Qpainter.
    But i just have a couple of push buttons on my widget.
    is there to transfer my widget to a thread other than the main thread of main window?!! or this is a stupid idea?

  • Lifetime Qt Champion

    No you can't paint widgets from another thread. However, you can generate the content to be painted (e.g. the Mandelbrot example)

    Out of curiosity, do you really need that much widgets ? Wouldn't a QGraphicsView/Scene combo be more suited ?

  • Thanks Samuel,
    actually my application is like an "scada" system and every widget on the main window is symbol of a sensor.
    when the operator clicks on every widget(symbol), all data (such as temperature trend and ...) can be seen in the second window that will be opened. Now when i want to close that window (or while opening) the main window will freeze.

    I inherited that symbols from Qpushbutton.
    why do you suggest QGraphicsView/Scene?? you think at this situation, opening the second window will not cause the main window to freeze?!
    And really thanks for your clue of "mandelbrotwidget". that will help me in threading because my app needs that for reading from tcp/ip and writing to database.

  • Lifetime Qt Champion

    Well, from what I remember of scada control screens, they can be graphically intensive and animated. The QGraphicsView framework would make more sense to do these kind of animations (or QML)

  • and for last question:
    assume you have a main window that an simple animation (such as moving a line) is shown. the moving (animation) process is performing through calling a function (AnimateFunc()) in main window by a Qtimer(500 ms). in this function (AnimateFunc()), the geometry of the line in the main window is changing randomly.
    Beside that, there is a dialog widget that is shown by a push botton in main window.
    the question:
    In the time of showing that dialog, the call for AnimateFunc() will be happened in every 800 ms or 900 ms and again returns to 500 ms.
    this happens because the gui thread is busy because of showing that dialog.
    How can i keep the calling interval time of AnimateFunc() fixed?
    what do you do as a specialist?
    using QGraphicsView, can i move them to separated threads??

  • Lifetime Qt Champion

    Not knowing the code nor the hardware, I can't really comment on that.

    What does the dialog do ?

  • platform: windows
    hardware: intel corei3 PC 32 bit
    the dialog has 5 push buttons that are initiated (enabled/disabled) at the beginning of the show with 5 Boolean has an ok/cancel too.
    when i click on ok, the variables take value with respect to the push buttons states. nothing more! the dialog has a style sheet too. it is inherited from QWidget and its parent is main window and i set it to Qt::Dialog.
    i just set its visibility on or off. its made in the start of the application on the heap.

  • Lifetime Qt Champion

    Sounds pretty lightweight…

    And what does your main window do ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.