Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Widget on Mac has a top and bottom border that is drawn on top of everything



  • Hey guys,

    Apologies for the spam "HELP WITH MAC" topics.

    I have a simple widget that acts as an image viewer. The widget window displays images as expected on Linux and Windows, but on Mac, I have top and bottom borders that get drawn over the image and I have no idea how to get rid of them.

    Screenshot from linux:
    correct_image

    Screenshot from mac:
    correct_image

    As you can see on the mac version, there is a border on the top and the bottom half of the image. How do I get rid of it?

    Here's the related code. I do not definite any style for the widget, I used the default created and then resize the window in my code as needed.

    void imageSelector::paintEvent(QPaintEvent *) {
        QPainter painter(this);
        bkgnd_scaled = bkgnd.scaled(this->size(), Qt::KeepAspectRatio);
        QRect rect = bkgnd_scaled.rect();
        QRect devRect(0, 0, painter.device()->width(), painter.device()->height());
        rect.moveCenter(devRect.center());
        painter.drawPixmap(rect.topLeft(), bkgnd_scaled);
    }
    

    Cheers,

    Nick



  • For anyone wondering what the solution was, I had unused QToolbar and QstatusBar, which were invisible on Linux and Windows, but appeared on Mac. Removing them from the .ui file fixed the issue:

    <ui version="4.0">
     <class>imageSelector</class>
     <widget class="QMainWindow" name="imageSelector" >
      <property name="geometry" >
       <rect>
        <x>0</x>
        <y>0</y>
        <width>400</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle" >
       <string>imageSelector</string>
      </property>
      <widget class="QMenuBar" name="menuBar" />
      <widget class="QToolBar" name="mainToolBar" /> #CULPRIT
      <widget class="QWidget" name="centralWidget" />
      <widget class="QStatusBar" name="statusBar" /> #CULPRIT
     </widget>
     <layoutDefault spacing="6" margin="11" />
     <pixmapfunction></pixmapfunction>
     <resources/>
     <connections/>
    </ui>
    

    Should I open a bug for the inconsistent cross-platform behaviour?

    Cheers,

    Nick


  • Lifetime Qt Champion

    Hi,

    Yes you can, but first check whether there's already something about this behaviour.



  • @SGaist I couldn't find anything about that. Where should I look for that information?


  • Lifetime Qt Champion

    Take a look at the bug report system


Log in to reply