Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to remove black border around widget?
Qt 6.12 LTS is out! See what's new in the release blog

How to remove black border around widget?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 12.5k 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.
  • B Offline
    B Offline
    bushlyamax
    wrote on last edited by
    #1

    Hello,
    I am writing Qt application under Linux for displaing electronic maps. After drawing onto QLabel and resizing window I have a black border around QLabel (before resizing everything is fine).
    I am drawing bitmap with Xlib function XPutImage to speed-up drawing

    @void MapView::paintEvent(QPaintEvent *)
    {
    GC context = XCreateGC(QX11Info::display(), winId(), 0, NULL);
    XPutImage(QX11Info::display(), winId(), context, scr->ximage, 0, 0, 0, 0, scr->W, scr->H);
    XFreeGC(QX11Info::display(), context);
    }@

    @MapView::MapView(QWidget *parent) :
    QLabel(parent)
    {
    setBackgroundRole(QPalette::Base);
    setAttribute(Qt::WA_PaintOnScreen);
    setAttribute(Qt::WA_NoSystemBackground);
    setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    setFrameShape(QFrame::NoFrame);
    setScaledContents(true);
    setMouseTracking(true);
    }@
    and the main window widget
    @ImageViewer::ImageViewer()
    {
    scrollArea = new QScrollArea;
    mapView = new MapView(scrollArea);
    scrollArea->setWidget(mapView);
    setCentralWidget(scrollArea);
    }@

    what is my mistake?

    !http://imageshack.us/photo/my-images/442/pic3o.png/(screenshot)!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      QLabel has a methods:
      [code]
      setFrameShape()
      setFrameShadow()
      setLineWidth() // set to 0?
      setMidLineWidth()
      [/code]
      maybe this will help you.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Have you tried drawing bitmap with Qt?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bushlyamax
          wrote on last edited by
          #4

          to Hostel:
          these methods did not made any effect
          I think that problem is bit deeper inside the Qt

          to Kxyu:
          I am trying to draw bitmap with XPutImage.
          All is right when i am drawing bitmap with
          @QImage im(bitmap, width, height, Q_RGBA......);
          label->setPixmap(QPixmap::fromImage(im));@
          but it is too slow for me

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

            As I understand, the problem is with custom painting in painEvent() and property Qt::WA_NoSystemBackground - without this property there is no black border but after my painting by XPutImage() my qLabel widget immidiately repaints with background color

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rturrentine
              wrote on last edited by
              #6

              Create a style with a 0 border width and call setStyleSheet.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bushlyamax
                wrote on last edited by
                #7

                setStyleSheet("QLabel {border: 0px;}") + custom paintEvent causes an internal error

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rturrentine
                  wrote on last edited by
                  #8

                  Where are you setting the stylesheet? In the MapView constructor? Not sure why a custom paintEvent would get in the way. We do it all of the time but without the custom paintEvent.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bushlyamax
                    wrote on last edited by
                    #9

                    I have tryed both - inside constructor and outside.
                    Another variant is to draw bitmap with OpenGL and GLWidget
                    @glDrawPixels(scr->W, scr->H, GL_BGRA, GL_UNSIGNED_BYTE, (const GLvoid *)scr->bitmap);@
                    and the same effect - black border around my GLWidget. I am in frustration!)

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bushlyamax
                      wrote on last edited by
                      #10

                      I think that Qt QScroll area works wrong - I have reimplemented it and had no problems with borders!

                      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
                      • Unsolved